mjohnson3091 Posted June 22, 2005 Posted June 22, 2005 I'm looking at creating a form layout dynamically from an XML document. The parsing of the XML data i'm fine with and the creating of the controls I think I'm ok with, it's just the naming of them. The code below is a cutdown example of what I'm using to draw the form. I'm using C# and hope to deploy this onto mobile devices at some point. // Loop around the number of Data items and draw the form for(intLoop=0;intLoop<dtData.Rows.Count;intLoop++) { switch(dtData.Rows[intLoop]["Type"]) { case "Button": { Button btn1 = new Button(); btn1.Width=dtData.Rows[intLoop]["Width"]; btn1.Height=dtData.Rows[intLoop]["Height"]; // ..... etc. for the properties this.Controls.Add(btn1); btn1.Visible=true; } } } In this example I'm using the name btn1, would I be better passing the names in the XML message? If so, how can I use the string field I get as a name (i.e.: If I pass the string "Button1" in the XML message and assign it to a string variable, strName, then will the new Button not take the name strName instead of its value)? Hope that makes sense. Thanks in advance. Quote
Machaira Posted June 22, 2005 Posted June 22, 2005 Unless I'm missing something, you just set the Name property like you would any other. Quote Here's what I'm up to.
mjohnson3091 Posted June 22, 2005 Author Posted June 22, 2005 Unless I'm missing something' date=' you just set the Name property like you would any other.[/quote'] No - you're right, it was me that was missing something this morning - like the brain I left at home! :p It has advanced onto another issue which I have, which is controlling the events of the newly created controls. I've managed to creat and handle the click event for the button without a problem, but when I try to handle the mouse events on an image I seem to have a problem. // img1 is my newly created PictureBox control img1.MouseMove += new System.Windows.Forms.MouseEventHandler(subWrite); private void subWrite(object sender, System.Windows.Forms.MouseEventArgs e) { bool test; if(mblnPenDown) { // How do I associate the Sender Object to the PitcureBox?? xxxxx.BackColor=Color.Blue; test=true; } } How do I associate the Sender Object to the actual picturebox I wish to use?? Quote
Administrators PlausiblyDamp Posted June 22, 2005 Administrators Posted June 22, 2005 you would need to cast sender to a picturebox. ((PictureBox) sender).BackColor = Color.Blue; should do the trick. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjohnson3091 Posted June 22, 2005 Author Posted June 22, 2005 you would need to cast sender to a picturebox. ((PictureBox) sender).BackColor = Color.Blue; should do the trick. A bit silly of me - works a treat mate, thanks. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.