|
System.Drawing.StringFormat class allows you to justify a text to left, right, top, bottom, center and middle of the clip rect. But I saw in Microsoft Word an option to justify text to both margin, so every line of text has the same width.
I checked the System.Drawing.StringFormat properties and didn't find out how to do this.
Please help me, thanks alot.
|
|
|
|
|
I've done a quick lookup, and you're right, it doesn't work, not for textbox, not for richtextbox. I read on a forum that it was just not possible at all, without using custom controls that you can buy/make.
Although I would hope that Framework 3.0 or GDI+ has this functionality somewhere. I can't help you with that, but you could point your question towards them (also).
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
I got the problem when using Graphics object to draw text, like this
Graphics g;<br />
g.DrawString("Text", font, brush, rect, format);
with format is an instance of System.Drawing.StringFormat
No way to strect the text lines to have the same width
Thanks for your answer anyway.
|
|
|
|
|
Hello All,
How can I edit a datagrid item faster. I have the following approach.
string LocalTimeToStore = null;<br />
DateTime dt;<br />
DateTime local;<br />
string LocalDateTime = null;<br />
<br />
for (int i = 0; i < LoggerDatagrid.Rows.Count - 1; i++)<br />
{<br />
LocalTimeToStore = LoggerDatagrid.Rows[i].Cells[1].Value.ToString();<br />
dt = Convert.ToDateTime(LocalTimeToStore);<br />
local = dt.ToLocalTime();<br />
LocalDateTime = string.Format("{0}/{1}/{2} {3}", local.Month, local.Day, local.Year, local.TimeOfDay);<br />
LoggerDatagrid.Rows[i].Cells[1].Value = LocalDateTime;<br />
}
Is there a method to edit the data grid cells and repopulate the same back? please help me
Keshav Kamat
India
|
|
|
|
|
Are you asking for better performance or less Lines of Code (shorter code)?
For the performance, I think it is best to just change the format, and not the actual value of the cells. This can be done by editing the CellStyle, either via the IDE (Datagridview > edit columns > DefaultCellStyle > CellStyle Builder > Format) or via code:
dgv1.Columns[0].DefaultCellStyle.Format = ...
Hope this helps...
Here an MSDN link to Formatting types[^]
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
hi
ok can u tell me a way, where in I can populate a dataset from a datagrid.
that would be helpful.
Keshav Kamat
India
|
|
|
|
|
If it is a bound datagrid, you just have to cast the datasource property into a dataset or datatable.
DataTable dt = (DataTable)dgv.DataSource;
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
thanks. i will try it.
Keshav Kamat
India
|
|
|
|
|
by the way,
how do I access a cell of this table that is created.
I need to modify the contents of this table. How do I do it?
Keshav Kamat
India
|
|
|
|
|
look up DataTable in Object Browser.
You can use DataTable.Rows[x].Cells[y].Value or something of the likes.
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
Hi i developed a windows application, after completion of the processing it has to write the results in to a file. I wrote code for this form_closing event. It is working fine when i closes the application. My problem is
If the system is shutting down with out closing the application it is not writing data in to the file. I dont know what event is fired when the application is closed by shutdown.
It is very important to store the results into the file.
Please Help me.
Thanks in Advance.
Ramu
|
|
|
|
|
|
Thank You Very Much.
This helps a lot for me.
Thank You
Ramu
|
|
|
|
|
just use the form closing event and use the FormCloseEventArgs object
and check if( e.Closereason == CloseReason.WindowsShutDown)
hope that is useful for u...
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Thank You very Much.
This helps me a lot.
Thank You
Ramu.
|
|
|
|
|
Hi,
I want to save/upload a file in sql database BUT WITHOUT using the upload object from c#, just a straight forward code. I already have the path of the file itself with fuill permission. Does anybody know how to do it?
Thanks
Dabsukol
|
|
|
|
|
Will this do the trick?
Adding binary data to a table[^]
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
Code is simple as below:
Process process = Process.Start("MSBUILD.EXE", "D:\\Common\\Common.sln /p:Configuration=Debug");
process.WaitForExit();
When I ran above code in C#, I got "ExitCode = 1" error, couldn't figure out why. Anybody please help?
Thanks a bunch.
Hazy
|
|
|
|
|
Hi.
I need to write a large text file from my application. Large means something like 200+ Megabytes.
What is the fastest way to do it? Using the static methods of the "File" class or using streams?? I am aware that either way, it'll take a long, long tine, but ...time is precious.
And another related question. It helps in terms of performance to write as much data as possible at a time, doesn't it?
Thanks.
|
|
|
|
|
blackjack2150 wrote:
And another related question. It helps in terms of performance to write as much data as possible at a time, doesn't it?
kind of depends what you mean by performance. but often yes.
1. The user starts the file save procedure and starts looking at email. The PC will look faster if your process is slightly less fast so smaller packets that don't block the disk queue might help.
2. The hard disk has issues. The program continually tries to write and fails. Because your packets are huge it fails more often as it's hard to find unbroken space that big and it has to attempt each write many times. (This would more likely be a problem on a network share for instance).
3. The hard disk is fast, is 0% fragmented and there's more ram and CPU power in the box than you could shake a stick at. This machine isn't going to slow down for anything so you might as well max the packet size and get the job done fast.
Do you need this file save to complete before the user continues? If not i would suggest sticking the save process in a background thread and maybe put a progress bar in the UI.
Russ
|
|
|
|
|
User interaction is not important for me. In fact is almost absent. I've converted my program to a console application, as I noticed that during the execution the UI got blocked. I know there are ways to avoid this, but I decided that it's not worth the effort.
If it helps I'll briefly describe what the program does:
I have a folder containing more than 7000 xml files which are news articles. I must read everyone of them and write to a file every distinct word in these xmls. It adds up to about 42000 words. I another file I must write the frequency of appearance of every word in every xml file, so there are 42000*7000 = a s...load of numbers to be written.
So, the user just starts the program, sits back and begins to read a book on programming.
It takes about 5 minutes to read the files and store the words in memory, another 5 to write the 42000 words to the first file, and writing the last file....well God knows, as I never had the patience to wait that much.
This file should have: (7000 * 42000 * 2) / 1024 /1024 ~= 560 MB.
The data structures I use are just basic arrays and matrixes. Does the word "matrixes" exist? Or should it be matrices?
So, what do you suggest?
|
|
|
|
|
Hi
well that does not sound like a I/O Performance problem. writing to streams is pretty fast.
i have an application that writes every day a 70GB Zip - File and it doesnt take more than 4 hours. and it gets slower the bigger the file gets. the first gb takes about 15 minutes.
is the whole data processing finished when your app writes the first file?
if not, i would say, the creation of the data used for your second file takes so long and not the write process of it..
greets
m@u
|
|
|
|
|
It seems to me that you can write the first file as you go, unless you want to write them alphabetically or something.
If you have a reasonable idea of the maximum number of digits for the frequency, you could write the second file as you go as well, just keep a Dictionary containing the word, the current count, and the offset to the position of the frequency.
blackjack2150 wrote: The data structures I use are just basic arrays and matrixes
I recommend a Dictionary.
blackjack2150 wrote: matrices
That is correct.
|
|
|
|
|
I mocked up a quick perf. test. You can run it yourself to see the results (in VS 2005).
Just make an empty console app. and past this code:
class Program<br />
{<br />
static string printme =<br />
"Fastest way to write a text file Fastest way to write a text file Fastest way to write a text file";<br />
<br />
static void Main(string[] args)<br />
{<br />
<br />
Stopwatch sw = new Stopwatch();<br />
sw.Start();<br />
<br />
<br />
test1();<br />
<br />
<br />
sw.Stop();<br />
Console.WriteLine(sw.Elapsed);<br />
<br />
<br />
sw.Reset();<br />
<br />
<br />
sw.Start();<br />
<br />
<br />
test2();<br />
<br />
<br />
sw.Stop();<br />
Console.WriteLine(sw.Elapsed);<br />
<br />
<br />
Console.Read();<br />
}<br />
<br />
<br />
static void test1()<br />
{<br />
TextWriter tw = new StreamWriter("test1.txt");<br />
for (int i = 0; i < 50000; i++)<br />
{<br />
tw.WriteLine(i + " " + printme);<br />
}<br />
tw.Close();<br />
}<br />
<br />
static void test2()<br />
{<br />
for (int i = 0; i < 50000; i++)<br />
{<br />
File.AppendAllText("test2.txt",i + " " + printme + "\n\r");<br />
}<br />
}<br />
}
I hope my logic is right, and if it is, you will hopefulyl see the same result as me. Streamwriter completes in a few seconds, and File.AppendAllText... takes forever.
There is also AppendText, but that returns a streamwriter and gives you the same result as test1.
Hope I helped.
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
blackjack2150 wrote: What is the fastest way to do it? Using the static methods of the "File" class or using streams?? I am aware that either way, it'll take a long, long tine, but ...time is precious.
I don't think that there is such a big difference. Most of the static methods in the File class are using streams anyway, so then the difference is just how you use the stream.
There might be a difference in writing a text stream, and encoding the text first and writing it as a binary stream, so that might be worth testing.
blackjack2150 wrote: It helps in terms of performance to write as much data as possible at a time, doesn't it?
That depends. The difference is hardly noticable unless the buffer size is very small or very big.
You should be aware of the large objects heap, though. Any object that is larger than 85 kb is allocated in the largs objects heap instead of the regular heap. The large objects heap grows when needed but never shrinks, so if you allocate a lot of large objects the program may allocate a lot of memory that is not returned to the system until the program ends.
---
single minded; short sighted; long gone;
|
|
|
|