|
Why on earth would you want to?
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
how can i have ellips form
MD_NADA
|
|
|
|
|
|
Hi everyone!
I've got a problem, coding in C#!
I have to create some PictureBox controls at runtime and the number of these will be specified at runtime too. Next, I should be able to target them by the name.
I mean I have to be able to generate the names as I need, at runtime, something like this:
<br />
for(int x = 0; x < xCount; x++){<br />
for(int y = 0; y <yCount; y++){<br />
public PictureBox "PictureBoxX"+x.ToString()+Y+Y.ToString() = new PictureBox();<br />
}<br />
}<br />
and then I should be able to access the control by its name and also be able to assign its properties!
There is a function in Javascript and Actionscript that make the object accesible at runtime by generating its name:
<br />
piece3 = "dangerous";<br />
x = 3; <br />
y = eval("piece" add x);<br />
trace(y);
or
<br />
name1 = "mike";<br />
name2 = "debbie";<br />
name3 = "logan";<br />
for(i = 1; i <= 3; i++) {<br />
trace (eval("name" add i));
but I couldn't find such a thing in C#!
Please help me with this! ((
Sojaner!
|
|
|
|
|
Would something like this help:
PictureBox temp = new PictureBox();
temp.Name = "PictureBoxX" + x.ToString();
MyForm.Controls.Add(temp);
Then to use your PictureBox:
PictureBox temp = (PictureBox) MyForm.Controls["PictureBoxX" + x.ToString()];
This will give you a mechanism for retrieving your PictureBoxes using a string, but it's not quite the same as eval in JavaScript, but it's probably safer.
-- modified at 17:28 Tuesday 27th June, 2006
|
|
|
|
|
Thanx a million, taking time to answer!
I've not tested it yet, but I'm almost sure it would work.
Sojaner!
|
|
|
|
|
Why do you think that you have to access the references to the picture boxes by name?
C# is not a script language, so there are no dynamic creation of variables. Use an array, a list, or a dictionary.
---
b { font-weight: normal; }
|
|
|
|
|
Thanx a million, taking time to answer!
Do you mean using a 2 dimention array of PictureBox controls?
And you mean, when coding in C#, from the beginning, you have to plane every object and other things and there is no way to decide what to do at runtime, like scripting languages?
|
|
|
|
|
Sojaner wrote: Do you mean using a 2 dimention array of PictureBox controls?
How you store the references depends on how you want to access them. If they are arranged in rows and columns in the form doesn't mean that you have to use a two dimensional array to keep track of them.
And you mean, when coding in C#, from the beginning, you have to plane every object and other things and there is no way to decide what to do at runtime, like scripting languages?
Yes. I have never really seen that as a limitation, though.
There are a lot of neat data structures like arrays, lists, linked lists, sorted lists, dictionaries, sorted dictionaries, queues and stacks that you can use to store data. A dictionary actually resembles what a script language uses to handle all variables.
I've built a lot of rather advanced web sites in VBScript too, and never needed to create variables dynamically there either. I believe that the Eval command is pretty much like the Goto command; it's never really needed, and your code gets better if you avoid it.
---
b { font-weight: normal; }
-- modified at 15:41 Wednesday 28th June, 2006
|
|
|
|
|
Yep, you are damn right!
I think I've got the point.
Thanx a million.
I tried what you told and everything went right.
Here is the code I wrote to solve the problem, do you like it?
PictureBox[,] pictureBoxes;
private void Form1_Load(object sender, EventArgs e)
{
pictureBoxes = new PictureBox[20, 20];
for (int x = 0; x < 20; x++)
{
for (int y = 0; y < 20; y++)
{
pictureBoxes[x, y] = new PictureBox();
pictureBoxes[x, y].Name = "pictureBoxX" + x.ToString() + "Y" + y.ToString();
pictureBoxes[x, y].Width = 10;
pictureBoxes[x, y].Height = 10;
pictureBoxes[x, y].Left = x * 10;
pictureBoxes[x, y].Top = y * 10;
pictureBoxes[x, y].BorderStyle = BorderStyle.FixedSingle;
pictureBoxes[x, y].Click += new EventHandler(PictureBox_Click);
this.Controls.Add(pictureBoxes[x, y]);
}
}
}
void PictureBox_Click(object sender, EventArgs e)
{
PictureBox temp = (PictureBox)sender;
ChangeColor(temp);
}
void ChangeColor(PictureBox pictureBox)
{
Random random = new Random();
Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
Graphics graphic = Graphics.FromImage(bitmap);
SolidBrush brush = new SolidBrush(Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)));
graphic.FillRectangle(brush, new Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
pictureBox.Image = bitmap;
}
Sojaner!
|
|
|
|
|
I would use a local variable to reference the picturebox that is created, so that I don't have to access it in the array all the time:
PictureBox pictureBox;
pictureBox = new PictureBox();
pictureBox.Name = "pictureBoxX" + x.ToString() + "Y" + y.ToString();
pictureBox.Width = 10;
pictureBox.Height = 10;
pictureBox.Left = x * 10;
pictureBox.Top = y * 10;
pictureBox.BorderStyle = BorderStyle.FixedSingle;
pictureBox.Click += new EventHandler(PictureBox_Click);
this.Controls.Add(pictureBox);
pictureBoxes[x, y] = pictureBox
You have forgotten to call Dispose on the Graphics object and the SolidBrush object when you are done with them.
Also, you should check if there already is an image in the picturebox, so that you can call Dispose on in after you replaced it.
---
b { font-weight: normal; }
|
|
|
|
|
Hi guys, I have an mdi form and I am trying to open a web form from one of the click events. The click event is for Contact us and I would like to open a web form that I have created, called contactus.aspx. How do I open the web form from the mdi form? Please help!!!
sasa
|
|
|
|
|
|
Hey guys, i was just wondering if there is something static funcitn in the Math, or string library that can evaluate a mathematical function...something like the following
String problem = "2+2";
Double answer = WonderfulFunction.Evaluate(problem); //wonderful function being the function im looking for...
just was wondering if it exists...if not then ill just have to create it...i figured there something out there...
Thanking yall in advance,
-- modified at 16:33 Tuesday 27th June, 2006
|
|
|
|
|
I've seen articles about classes like that here on CP. Probably searching for "parse" "math" "string" etc. would turn up the result you need.
|
|
|
|
|
I found this article here[^]
I've tried to follow because that sounds like my problem, so my code looks like this.
this.tbAdapter.fill(dataSet.tb);
this.dataSet.tb.select();
that still gives me record 1, instead of the one I want. What am I doing wrong?
-- modified at 16:41 Tuesday 27th June, 2006
|
|
|
|
|
Hello
I have a toolbox in my application which will allow user to drag and drop the toolbox controls on the Tabcontrol.
The baseline is, main toolbox item is Button, I want to implement dragdrop event of button on TabCOntrol.
I have done following things:
1. Set Allow Drop property of TabControl to true.
2. Implemented DragDrop event for button. But I observed that control does not go to that handling even after dragdrop
Can anyone pls suggest me how can i achieve this?
Thanks in advance.
|
|
|
|
|
I have following unicode characters in my application
Languages.Add("de-DE", "Deutsch (Deutschland)");<br />
Languages.Add("en-US", "English (USA)");<br />
Languages.Add("zh-CHS", "汉语 (简化)");<br />
Languages.Add("ja-JP","日本語");<br />
Languages.Add("fr-FR","Français");<br />
Languages.Add("es-ES","Español");<br />
Languages.Add("ru-RU","Русский");<br />
Languages.Add("pt-PT","Português");<br />
Languages.Add("it-IT","Italiano");<br />
Languages.Add("ar-EG","العربيّة");<br />
when I try saving the file, I get error as this file can not be save? can anyone guide me how can I save this class file?
Thanks in advance.
|
|
|
|
|
Well, I did it, I used Save as Encoding: Unicode (UFT-8 without signature)
|
|
|
|
|
I'm relatively new to C# programming, but I am using it to develop an app on the .NET Compact Framework. This works fine, I can deploy it via USB to my device and so on. However, debugging it on the device is a bit of a pain because my app slows waaaay down when sending the debug status info back to my PC. If I take the exe and run it on my PC, it actually runs (mostly) fine and is pretty nifty. However, what I would love to do is run it in the debugger on my PC. I'm hoping it would get better performance for debugging that way. But I can't figure out if or how I can do that. The only options for debugging seem to require a device, either physically connected or through an emulator.
Anyway, I hope I'm not missing anything too obvious; I'm new to VS2005 as well as C#. I also would prefer not creating a regular C# project that happens to use the same source files.
Thanks!
|
|
|
|
|
I haven't ventured into vs 2005 yet but in vs 2003 there is an emulator for the smart apps, (PPC and Win CE). You are given the option to select either one in vs 2003.
Is this available in 2005? Not sure but it's worth mentioning.
Gav
|
|
|
|
|
Well, as the title says I want to save the current state of a Windows.Form object. I'm currently investigating on doing this with xml-serialization, but I don't know if this is the way to go. I don't need a complete essay about that (I would take that, too) but a hint that points me into the right direction. So, can someone help me out please?
Greetings
|
|
|
|
|
You won't be able to serialize a Form object. It's not serializable. What you can do is serialize the state of the application's data, and then reload that instead. XML serialization should work fine for that, but you might as well use the BinaryFormatter because it's faster and more compact.
If you also want to save the state of individual controls on a form, then you better hope that you're using some good 3rd party controls, like Infragistics. The MS inbox controls suck, and as such, don't provide runtime serialization APIs. But some 3rd party controls will save user configured settings for you, which is a nice feature for most apps.
Josh
|
|
|
|
|
Binary formatter will not work if the class changes. Meaning if you try to read a config file that was written before changes were made to the class. Xml serialization is a safer way to go.
Just create a simple class that hold the information you require and make it XML serializable. Use my article[^] if you need help with the serialization.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
If I got that right: Due to containing interfaces many classes can't be serialized. I want to save the state of my windows form. So I need to serialize elements of this form. These are Controls (Labels and UserControls). If the above applies, I see no way doing so, except serializing lets say the Text of a Label and then later deserialize the string, create a new Label and set the Text to the deserialized string, which is a really bad situation. Is there any better way?
|
|
|
|
|