Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...