|
Use a Hashtable with the filename as key. That should make it considerably faster to locate the items.
---
b { font-weight: normal; }
|
|
|
|
|
What Guffa said. If you still want to continue with your approach, you could try
1. Does sFileListStruct have to be a struct/code>? Things would be much faster if it's a <code>class instead.
2. converting the ArrayList to List<sFileListStruct>. This will work only if you're using .NET 2.0. This saves the unboxing cost when you read the struct out of the list.
3. Overriding Equals in your struct should help things too. I've read that the default implementation of Equals, which is what IndexOf uses, uses reflection to compare field values.
|
|
|
|
|
Hi i am stumped on how to insert characters into a string so it can display correctly. for instance i am wanting to format a string (ex "19999"). To be displayed as 199.99 (to show a price of $199.99 instead of $19,999). Also to go a bit further i would if the price did reach in the thousands (ex 121499) i would need it to show as 1,214.99. I've looked for some format property but i couldn't find anything
Thanks in advance
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Since you constantly want to change 123456 into 1,234.56 then I suggest converting the string into a decimal first, then divide it by 100 and display it.
You can use the {0:c} currency formatting to display the '$', the ',' and '.'
Here's[^] a good article on string formatting in C# just in case you need it.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
Try this:
string output = (value / 100.0).ToString('N');
the 'N' style gives your number to two decimal places and comma seperates the thousands.
Regards,
Rob Philpott.
|
|
|
|
|
hi this is my code for get CPU ID :
string cpuInfo = String.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{ // only return cpuInfo from first CPU
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
return cpuInfo;
but in my system, it is not working correctly(and why in another computer it worked correctly ?)
the error that was shown me : Object reference not set to an instance of an object.
How to solve problem ?
thanks .
|
|
|
|
|
The ProcessorId isn't what you think it is. It's not serial number that can be used for some kind of compy protection. It's a field that describes the capabilities of the processor:
ProcessorId
Data type: string
Access type: Read-only
Processor information that describes the processor features. For an x86 class CPU, the field format depends on the processor support of the CPUID instruction. If the instruction is supported, the property contains 2 (two) DWORD formatted values. The first is an offset of 08h-0Bh, which is the EAX value that a CPUID instruction returns with input EAX set to 1. The second is an offset of 0Ch-0Fh, which is the EDX value that the instruction returns. Only the first two bytes of the property are significant and contain the contents of the DX register at CPU reset???all others are set to 0 (zero), and the contents are in DWORD format.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
serverTcpConnection = new TcpClient(popServer, port);
does not work.
Thanx.
|
|
|
|
|
You cannot bypass the proxy. Either the administrator of the proxy machine has to open up the port for you, or, you have to tunnel it through some port which the proxy keeps open. Typically, proxies keep port 80 for HTTP open. You could write a webservice that runs on a machine that has access to the port you want and then simply have your client call the webservice instead.
|
|
|
|
|
I've derived my own GradientListView class from the ListView control to try and draw a gradient background. I'm able to draw the gradient background just fine by overriding the OnPaintBackground event, but the ListView items no longer appear in the ListView. Is it an all or nothing deal?....Do I need to handle all the painting events if I override one of them? If I comment out the SetStyle command in the constructor the ListView shows the items correctly, but obviously without the gradient background.
public GradientListView()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint |
ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
}
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
{
PaintRectangle(this.ClientRectangle, this.BackColor, Color.Black, pevent.Graphics);
}
protected void PaintRectangle(Rectangle Rect, Color RectColor, Color RectBorderColor, Graphics g)
{
Pen LinePen = new Pen(RectBorderColor, 10);
g.DrawRectangle(LinePen, new Rectangle(Rect.X, Rect.Y, Rect.Width - 1, Rect.Height - 1));
LinePen.Dispose();
Rect = new Rectangle(Rect.X + 1, Rect.Y + 1, Rect.Width - 2, Rect.Height - 2);
SolidBrush bgBrush = new SolidBrush(RectColor);
g.FillRectangle(bgBrush, Rect);
bgBrush.Dispose();
LinearGradientBrush brush;
Rectangle BottomRect;
BottomRect = new Rectangle(Rect.X, Rect.Height-((int)(Rect.Height / 3)), Rect.Width, Rect.Height / 3);
brush = new LinearGradientBrush(
new Point(BottomRect.Width / 2, BottomRect.Top - 1),
new Point(BottomRect.Width / 2, BottomRect.Bottom),
RectColor,
ControlPaint.Dark(RectColor));
g.FillRectangle(brush, BottomRect);
brush.Dispose();
}
|
|
|
|
|
If you have the control set to OwnerDraw then it means you will draw everything.
Have no fear, though, since you can override Paint and then just call base.Paint().
See if that corrects the drawing problem.
As to your user name.....BRILLIANT!
|
|
|
|
|
Thanks for the response, unfortunately the drawing problem still persists even after overriding the OnPaint as you suggested as well as the Draw Events....see below:
class GradientListView:System.Windows.Forms.ListView
{
public GradientListView()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint |
ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
{
base.OnDrawColumnHeader(e);
}
protected override void OnDrawItem(DrawListViewItemEventArgs e)
{
base.OnDrawItem(e);
}
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
base.OnDrawSubItem(e);
}
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
{
PaintRectangle(this.ClientRectangle, this.BackColor, Color.Black, pevent.Graphics);
}
protected void PaintRectangle(Rectangle Rect, Color RectColor, Color RectBorderColor, Graphics g)
{
LinearGradientBrush brush;
Rectangle BottomRect;
BottomRect = new Rectangle(Rect.X, Rect.Height-((int)(Rect.Height / 2)), Rect.Width, Rect.Height / 2);
brush = new LinearGradientBrush(
Rect,
RectColor,
Color.White,
45);
g.FillRectangle(brush, Rect);
brush.Dispose();
}
}
Any other thoughts ?
-- modified at 11:43 Monday 23rd October, 2006
|
|
|
|
|
i want to pass variable from one calss "form1" to another class "form2"
|
|
|
|
|
m.m._2007 wrote: i want to pass variable from one calss "form1" to another class "form2"
Try this article[^]
|
|
|
|
|
|
First i tried to do this with following code: System.Data.DataTable.Select(System.Data.DataColumn.ColumnName + " = NULL");
but this didn't work!
so how should i modify my syntax to get the reult i want to have?
|
|
|
|
|
Try " is null" instead.
---
b { font-weight: normal; }
|
|
|
|
|
yep this is the solution!
|
|
|
|
|
I want to cancel the minimize event and instead minimize to tray....
Thanks in advice
Alocto
:-DProgramming is heaven
|
|
|
|
|
I believe this should do the trick, just use the Forms Resize event since it is called when the Form is minimised.
private void Form1_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = false;
notifyIcon1.Visible = true;
}
}
|
|
|
|
|
It just dont cancel the minimize event......
Im kinda looking for a way to stop the event because it still minimizes before hiding.....
Alocto
:-DProgramming is Heaven
|
|
|
|
|
Copy the following method into your form.
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0112)
if (((int)m.WParam & 0xFFF0) == 0xF020)
return;
base.WndProc(ref m);
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi everyone,
I've been having a problem when using ShowDialog (more that it doesn't do what I want it to do )
I've got a main form, from which I create a child form which I want to always be available (I use Form.Show() to show it).
Later on, the main form will then show dialog forms (using Form.ShowDialog()). The problem is that doing this causes the child form (which I want to always be available) to be blocked along with the main form, so the user can only use the new dialog form.
Is there a simple way around this? I'd prefer not to have to change using ShowDialog, because I do this all over the place. Can I just change what I do with the child form I want to always be available?
Here's a quick example piece of code which has the effect I'm trying to explain:
private void MainForm_Shown(object sender, EventArgs e)<br />
{<br />
Form alwaysAvailableChild = new Form();<br />
alwaysAvailableChild.Text = "Should be Always Available";<br />
alwaysAvailableChild.Show();<br />
<br />
Form dialog = new Form();<br />
dialog.Text = "Dialog";<br />
dialog.ShowDialog();<br />
}
Cheers in advance.
|
|
|
|
|
When you show a form with ShowDialog() you will not be able to use other forms, because the form you just showed is showed like a dialog....
Which means that other forms not will be available before the dialog is closed again...
So if you just use Show() it should not give any problems....
Hope it solved your problem..
Alocto
:-DProgramming is Heaven
|
|
|
|
|
I realise that this is an easy option to solve the problem (although I'd have to manually disable the main form myself)... but I was more wondering if there was a way to have a completely "seperate" window from the rest of the application, so that when the main window shows a dialog, my "seperate" window will be unaffected.
The reason I'm asking is that I've got my application which shows dialogs here, there, and everywhere, and now I want to add a, sort of, help window, which is always available (preferably without moving it into a seperate application).
|
|
|
|