|
Hi, i have a form with a panel. In this panel, it allow the shapes drawn (using graphicspath) to be drag and drop. However, there is the flickering problem whenever i drag any of the shapes. i tried to use the SetStyle function like below:
public class DoubleBufferPanel : Panel<br />
{<br />
public DoubleBufferPanel()<br />
{<br />
this.SetStyle(ControlStyles.DoubleBuffer |<br />
ControlStyles.UserPaint |ControlStyles.AllPaintingInWmPaint,<br />
true);<br />
<br />
this.UpdateStyles();<br />
}<br />
}
however, it generates the error below:
An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll<br />
<br />
Additional information: Invalid parameter used.
Any suggestion on what should i do?
Thanks in advance
|
|
|
|
|
Hello,
I would assume that the exception is not accuring in the classes constructor.
Have you overriden the "OnPaint" method?
Please show us more code and do some debugging!
All the best,
Martin
|
|
|
|
|
Hi,
you must use the line numbers:
- tell Visual to show line numbers (see my sig, tip 1)
- look at the exception's line numbers (see my sig, tip 2)
Good luck !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
This should be easy, however I keep getting it wrong I'm completely missing something, and google isn't being much help. I guess its to late... not sure.
I need to calculate how many addresses are in a range. So what i'm looking for is a formula to find this.
example i have
10.126.0.1 through 10.127.0.1 i want to know how many addresses are in between the range.
Thanks!
|
|
|
|
|
One presumes you need to take an IP address, split it into four numbers, and check if each of those numbers is within the ranges specified by doing the same to your range IP addresses.
string [] lower = "10.126.0.1".Split(new char [] {'.'} );
string [] upper= "10.127.0.1".Split(new char [] {'.'} );
string [] range = newIp.Split(new char[] {'.'} );
// check here that range contains 4 strings
bool match = true;
for(int i=0;i<4;++i)
{
match &= (int.TryParse(lower[i]) >= int.TryParse(range[i]));
match &= (int.TryParse(upper[i]) <= int.TryParse(range[i]));
}
Something like that would work, but it has levels of nastiness.
1 - it assumes the values coming in are all valid numbers. Using TryParse would add a lot of code, you could add a try/catch ( if it blows up, they can't match ).
2 - it parses range[i] twice, instead of storing it.
But, it should work, and should give you a good starting point. Assuming my assumptions about the rules that define a number being 'in the range' are correct.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
First, I really appreciate the reply!
Your suggestion might work. (i verify the numbers are in range before the program reaches this point so i'm not worried about it being outside) and I have already converted the numbers to an array of 4 integers when its time to calculate the total, however it's quitting time for me now, so i'll have to wait until tomorrow to try it. But in the mean time if anyone else has a suggestion I'd still rather use a formula for the calculation.
|
|
|
|
|
What about
a method like
int GetIPasint(string ipAddress)
{
string [] ip = ipAddress.Split(new char[] { '.' } );
int ipAddress = 0;
for(int i = 0; i < 4; ++i)
{
int portion;
if (int.TryParse(ip[i], out portion)
{
ipAddress += portion << (4-i);
}
}
return ipAddress;
}
Hopefully, that would work to give you values that fall between the ranges. Although, I have some doubts, I have to say, it's worth a shot.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
the number of addresses in the interval[ a.b.c.d , e.f.g.h ]
equals num32(e,f,g,h) - num32(a,b,c,d) + 1
where num32 is the 32-bit number formed by those 4 byte values, as in:
num32(a,b,c,d) = ((((((a<<8)+b)<<8)+c)<<8)+d);
BTW: you may save a few lines of code using IPAddress.GetAddressBytes(),
unfortunately there seems to be no method IPAddress.GetAddressInt32() !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
WOW exactly what i needed!!!! THANK YOU!!!
|
|
|
|
|
How can I load a XML into a rich text box?
l_szCurrentFile = m_szDirectory + "\\" + m_oTabControl.SelectedTab.Name.ToString();
rtbDoc.LoadFile(l_szCurrentFile, RichTextBoxStreamType.RichNoOleObjs);
I get an invalid file type error with this
|
|
|
|
|
I think your problem is caused by "RichNoOleObjs ." According to the help file, "This value is only valid for use with the SaveFile method of the RichTextBox control."
Try using PlainText (or UnicodePlainText .)
BDF
|
|
|
|
|
<br />
<br />
using (StreamReader sr = new StreamReader(@"N:\test2.xml"))<br />
richTextBox1.Text = sr.ReadToEnd();<br />
<br />
good luck
|
|
|
|
|
I have to write a program converting a csv file into a huge xml file, about 100 elements.
Is the best way to just create a class xmlfile.cs
then read the info from another class pass the values to xmlfile one by one, then when done use xmlwriter, in the same class, to write the whole file?
Is there a better way?
Thanks
|
|
|
|
|
There are several CSV parsers on this site, have you searched them?
Generating the XML...I guess fill them into an array and serialize that using an XML serializer. Will that work?
|
|
|
|
|
Yes I have seen and practiced with a couple. It may be more overhead but i actually like using the excel object to parse the files I find it to be easier and it works better in my head.
Thanks
|
|
|
|
|
Ok. Is your question answered, then, regarding serializing the CSVs to XML file?
|
|
|
|
|
Yes i am new to xml and serialization is a much better way than i was doing. Thanks again
|
|
|
|
|
you may also want to look at vtd-xml
http://vtd-xml.sf.net
|
|
|
|
|
hi friends!
i have little prob i u can plz help me.
Q.1 I have to enter login and logout time in database in SQL through c# the prob is everytime i try to do it ,it goes in two diff rows is there any other way tht i can feed it in same row n later find total used time?????
Q.2 how to display time coz using DateTime.Now.TimeOfDay.ToString() gives me time in miliseconds bt i want it only till minutes?
plz help me guys.......
|
|
|
|
|
Q.1 doesn't make much sense. If you need to start both the sign-in and sign-out times in a single row, then your row will need 3 column values:
-An ID: e.g. some unique value identifying the row.
-The sign-in time
-A nullable sign-out time.
When you first sign in, create a new row with a new ID, the sign-in time, and a null sign-out time. When you sign out, find that row by the unique ID and update it's sign-out time.
Q.2 Sounds like you're looking for DateTime.Now.ToShortTimeString() .
|
|
|
|
|
thanks friend it worked though the first one still not perfect thanks
|
|
|
|
|
I have an array of some odd 100k 3d points. I want to rotate them around an axis. What is the quickest way of rotating them? I suspect that it might have something to do with a matrix, but I dont know much about them.
Thanks,
|
|
|
|
|
Yes, matrices are what you need to look into. Are you using XNA? MSDN describes the XNA Matrix class[^]. See the links in the article for How-To's on how to transform (e.g. move, rotate, etc.) 3d points using matrices.
|
|
|
|
|
No I am not using XNA, or WPF. All I really have is a custom structure made up of three double values to define a 3d point. I see that there is a matrix class in c#. And in actuallity I would be fine even with a 2d rotation, though 3d would obviously be better.
|
|
|
|
|
GreenGiant83 wrote: I would be fine even with a 2d rotation
Check out System.Drawing.Drawing2d.Matrix class. There are other classes in the Drawing2d namespace that may help you with your rotations.
Alternately, you *could* use the free Lutz Reflector[^] tool to see how XNA's Matrix class rotates 3d rotations, then do a little copy & paste job into your own code.
|
|
|
|