|
From where is this code called? You might consider not even redrawing the image synchronously, but enabling double buffering and calling Control.Update when moving the rectangle. This will cause the control to redraw the image in a background thread and flip the buffer to the control's surface when resources are available. See the documentation[^] for the ControlStyles enumeration, which you pass to Control.SetStyle .
Also note that you should do as much drawing as possible in an override to OnPaint (do not handle events when extending controls, which is a more robust solution than handling events on an external class), being sure to call base.OnPaint when appropriate. In that case, use PaintEventArgs.Graphics that is passed to you and do not dispose it yourself, like you normally would if you use Control.CreateGraphics . The latter call can be expensive, too, so depending on how your code above is used - which is why I asked - could also be the source of poor performance if you're creating a new Graphics for each call to OnMouseMove .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank You very much, double buffering is perfect for my application
-------------
Lukasz Szymik
|
|
|
|
|
Hi folks!
In another forum someone was asking how to serialize a class like this using XmlSerializer:
class Test
{
public Test() {}
private int someval;
public int SomeVal
{
get { return someval; }
set { someval = value; }
}
private object tag;
public object Tag
{
get { return tag; }
set { tag = value; }
}
}
Whether XmlSerializer is able to serialize an instance of this class or not is depending on the value of Tag , strangely enough.
When Tag is an int or string for example, everything works fine.
When Tag is an int[] , for example, you get an exception during serialization.
That's the first thing I can't understand. Having an int[] property in the class serializes just fine.
At first I thought the XmlSerializer is having problems when it doesn't know the type to serialize beforehand, but then I changed the definition of the class a bit and suddenly it worked:
Only by adding this property:
private int[] dummy;
public int[] Dummy
{
get { return dummy; }
set { dummy = value; }
} I could get the XmlSerializer to not throw an exception when serializing the class with an int[] assigned to the Tag property!
Can anyone imagine what's going on there?
Thanks in advance,
mav
|
|
|
|
|
The type has to be serializable. Read the documentation[^] for the SerializableAttribute class, as well as Serializing Objects[^] in the .NET Framework SDK.
Also note that the SerializableAttribute is not, by default, inheritted like some other attributes.
If you assigned a Control or Control -derivative to the Tag property, for example, it would not serialize despite the fact that its indirect base class MarshalByRefObject is marked as serializable because the SerializableAttribute is not inheritted. In your case with intrinsics and arrays, they are serializable. The class declaration (keeping in mind than any array you declare extends System.Array ) in the .NET Framework SDK which tell you which classes are marked as serializable.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for your reply, Heath!
I had flagged the class as [Serializable] , of course, but didn't write it in the sample code, sorry.
What you describe is more or less what I thought about serialization so far.
But this doesn't explain the behaviour I get (or perhaps I'm just too dense to see it):
Class without the Dummy property and an int assigned to Tag serializes OK.
Class without the Dummy property and an int[] assigned to Tag throws exception.
Class with the Dummy property and an int assigned to Tag serializes OK.
Class with the Dummy property and an int[] assigned to Tag serializes OK.
I'd assume that Tag wouldn't get serialized at all, because object isn't serializable by default.
But obviously XmlSerializer does serialize the Tag property.
And whether this serialization succeeds or fails is depending on other attributes/properties of the same class. That's what strikes me odd...
Still puzzled,
mav
|
|
|
|
|
Assume that I have a treeview with few node, I would like to select the node, press F2 or right click on that node, choose "Rename", and a textbox will appear to let me change the text of that node (include validtion if needed, number only for example), end accept changes when I press enter...
Show me the Idea for this problem
Thankx!
|
|
|
|
|
Here is the idea for "How to rename a tree node on key press (F2) and via a right-click menu":
Controls added: button1, treeView1, contextMenu1, menuItem1...
- Use the button to add nodes to the tree
- Add the corresponding events for the following..
<br />
private void RenameNode()<br />
{<br />
if (this.treeView1.SelectedNode != null)<br />
{<br />
this.treeView1.LabelEdit = true;<br />
this.treeView1.SelectedNode.BeginEdit();<br />
}<br />
}<br />
<br />
private void treeView1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.F2){RenameNode();}<br />
}<br />
<br />
private void menuItem1_Click(object sender, System.EventArgs e)<br />
{<br />
RenameNode();<br />
}<br />
<br />
private void treeView1_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)<br />
{<br />
this.treeView1.LabelEdit = false;<br />
}<br />
<br />
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
this.menuItem1.Enabled = (this.treeView1.SelectedNode != null);<br />
}<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
this.treeView1.Nodes.Add(new TreeNode("text here..."));<br />
}<br />
Hope this helps. Cheers
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
And you have the AfterLabelEdit [^] event fired by the TreeView control where you can validate the new text, and cancel it if necessary.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Nice input Luis.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Hi,
I'm trying to use the Microsoft.Web.Services2.Messaging.
ISoapFormatter
but I receive this error:
System.Xml.XmlException: Reference to undeclared parameter entity, 'meetingmaker'.
at System.Xml.XmlLoader.ExpandEntityReference(XmlEntityReference eref)
at System.Xml.XmlEntityReference.SetParent(XmlNode node)
at System.Xml.XmlNode.AppendChild(XmlNode newChild)
at System.Xml.XmlLoader.LoadAttributeChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadAttributeNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadChildren(XmlNode parent)
at System.Xml.XmlLoader.LoadElementNode()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at Microsoft.Web.Services2.SoapEnvelope.Load(Stream stream)
at Microsoft.Web.Services2.Messaging.SoapPlainFormatter.Microsoft.Web.Services2.Messaging.ISoapFormatter.Deserialize(Stream stream)
at WebSemantica.SoapSmtp.Mailbox.EndReceive(IAsyncResult result) in c:\wsf-projeto+final-julio\wsf-projeto final\websemantica\zutil-soapsmtp\mailbox.cs:line 308
----------------------------------------------------------
the code I'm using is (line 308 is the last line):
UTF8Encoding encoding = new UTF8Encoding();
SimpleMailMessage m = messagesArray[i];
ISoapFormatter formatter = new SoapPlainFormatter();
MemoryStream stream = new MemoryStream( encoding.GetBytes( m.TextDataString
) );
stream.Position = 0;
envelopes[i] = formatter.Deserialize( stream );
----------------------------------------------------------
if I print the xml (the "m.TextDataString") the result is:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY meetingmaker "http://websemantica.puc-rio.br/2004/06/meetingmaker/meetingmaker#">
<!ENTITY ical "http://www.w3.org/2002/12/cal/ical#">
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
]>
<soap:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsa:Action>InvokeCoordinator</wsa:Action><wsa:MessageID>uuid:d905eba6-7ed8-420d-a297-b8625751f63c</wsa:MessageID><wsa:To>urn:websemanticaproxy</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-71318c38-b4e8-46a5-af91-72348be37458"><wsu:Created>2005-02-27T00:12:47Z</wsu:Created><wsu:Expires>2005-02-27T00:17:47Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><string xmlns="http://tempuri.org/">
<rdf:RDF
xmlns:meetingmaker="&meetingmaker;"
xmlns:ical="&ical;"
xmlns:rdf="&rdf;"
xmlns:rdfs="&rdfs;"
xmlns:xsd="&xsd;"
>
<meetingmaker:MeetingMaker rdf:ID="meetingmaker_id">
<meetingmaker:criteria rdf:datatype="&xsd;string">majority</meetingmaker:criteria>
<meetingmaker:algorithm rdf:datatype="&xsd;string">parallel</meetingmaker:algorithm>
<meetingmaker:uid rdf:datatype="&xsd;string">julio@ntime.com.br-02-26-2005 09:12:45</meetingmaker:uid>
<meetingmaker:vevent>
<ical:Vevent rdf:ID="vevent_id">
<ical:location rdf:datatype="&xsd;string">Puc</ical:location>
<ical:summary rdf:datatype="&xsd;string">Apresentacao de Trabalho</ical:summary>
<ical:dtstart rdf:datatype="&xsd;datetime">12-10-2004 10:00:00</ical:dtstart>
<ical:dtend rdf:datatype="&xsd;datetime">12-10-2004 11:00:00</ical:dtend>
<ical:contact rdf:datatype="&xsd;string">julio@ntime.com.br</ical:contact>
<ical:attende>
<rdf:Bag rdf:ID="vevent_ateende">
<rdf:li rdf:datatype="&xsd;string">kid@teccomm.les.inf.puc-rio.br</rdf:li><rdf:li rdf:datatype="&xsd;string">fred.kid@gmail.com</rdf:li><rdf:li rdf:datatype="&xsd;string">fsilva@inf.puc-rio.br</rdf:li>
</rdf:Bag>
</ical:attende>
</ical:Vevent>
</meetingmaker:vevent>
</meetingmaker:MeetingMaker>
</rdf:RDF></string></soap:Body></soap:Envelope>
(whitch is a valid XML, at least the Internet explorer open it...)
|
|
|
|
|
How was this XML generated in the first place? I suspect that if you change the order of the entities whichever you put first will be what's reported in the exception.
Please post a snippet of your code that you're using to generate the XML (SOAP) to hopefully give us a better idea of what could be wrong.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I can get a collection of system variables, and the collection of controls my form has in it. But, is there a method to get the collection of class variables, and possibly local variables to a function? This is for error-handling purposes, so as much information about my runtime that I can get, the better. This is a windows app, not asp. Thanks!
|
|
|
|
|
DougW48 wrote:
This is for error-handling purposes, so as much information about my runtime that I can get, the better.
It sounds like you are trying to break encapsulation which would really muddy and complicate the design of your application.
If an unexpected error condition arises you should throw an exception. If you need to you should create an exception class and design it so that it can be loaded with the error information so that the error handler (the catch block) can see the necessary information. However you should think carefully about whether you actually need the information or if it is just a quick solution now that will muddle things in the future.
Cada uno es artifice de su ventura
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
It is possible to get values of class level variables using reflection, but I don't think it is possible to write generic code to get values of local variables.
Regards
Senthil
My Blog
|
|
|
|
|
How do I make a service that will not appear in the process list when it is done?
Specifically, I want to have an invisible service that would restrict all traffic on a computer. And no, this is not being done with malicious intent, but it does have to be invisible for other reasons.
Cheers,
Jim
|
|
|
|
|
|
You can hide processes from task manager but as far as I know you cannot hide a service from the services list.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
|
That might be a way to do it and also svchost.exe I guess. I'm talking about "hiding" of course. I never needed it but a friend of mine was able to do it in C++ (I remember using some APIs) But what I know is, it is not legal because you'll have to reconfigure some system settings and the user won't be able to see it in the list so won't have the chance to end the app... Also, another way is registering the app as a service so it won't be in the process list but will be visible to advanced users in the services. If I remember right, it was something like this "RegisterServiceProcess lib "kernel32" (lngProcessID As Long) As Long" via WScript..
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Colin Angus Mackay wrote:
The only way I could think of was with dllhost
Well , Colin , I'd be pleased if you tell me how you can hide it in this way.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
|
hi all, am new to C# programming and i got a little problem
am having some text boxes in my form, and i want the mouse cursor to move automatically to the next textBox when the user inputs data in the preceding textBox. Just like when you enter the WinXP serial, u don't have to click 'TAB' to move to next TextBox.
thnx for ur help.
|
|
|
|
|
You can subscribe to the KeyPress event and check if the textbox has got the required number of characters. If it has, you can move focus to the next textbox. Something like
public void KeyPress_textBox1(...)
{
if (textBox1.TextLength == 5)
{
textBox2.SetFocus();
}
}
Regards
Senthil
My Blog
|
|
|
|
|
thnx for ur help,
one more thing, could I determine which data type could be entered in the text box, i.e. if the user entered "floating" no. for example it doesn't move the cursor. The user should enter "integer" for the cursor to move to the nexr text box.
|
|
|
|
|
You can use the Parse method on the Int32 class. Something like
<br />
...<br />
if (textBox1.Length == 5)<br />
try<br />
{<br />
Int32.Parse(textBox.Text);<br />
textBox2.Focus();<br />
}<br />
catch(Exception)
{<br />
}<br />
}<br />
Regards
Senthil
My Blog
|
|
|
|