|
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?
|
|
|
|
|
Hi!
In C# v2.0 (Visual Studio 2005), there is a file, named Settings.settings in the properties folder in the Solution Explorer window, there you can assign some settings in different types and so you can assign a property like this:
Name: FormPosition
Type: System.Drawing.Point
Scope: User (Take care of this, it made me crazy to get this point: Application scope, is read-only and it will be the same as the value you gave to it at the beginning and you can not change it at runtime! But User scope is made to be assigned both at the beginning and at runtime. )
Value: 100, 100
and then at runtime, you can access this settings by using this code:
<br />
Point formPosition = global::YourNamespace.Properties.Settings.Default.FormPosition;
and even you can change the value at runtime this way:
<br />
Point formPosition = new Point(MyForm.Left, MyForm.Top);<br />
global::YourNamespace.Properties.Settings.Default.FormPosition = formPosition;
These values will be automatically stored in the registry of windows, and in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\RNG and in binary mode that is coded and not recoverable by users, but by your application.
Hope you could use it!
Sojaner!
|
|
|
|
|
Is there any way i can attach a database (oledb or whatever) to a DataGridView without filling an offline dataset first? So basically execute an SQL query against a database and display the results in a datagridview (without using .Fill(...) because it takes forever)
Thanks a lot,
Wouter
|
|
|
|
|
|
Thanks for your reply, I tried it but it seems the .DataBind() method has disappeared from the DataGrid (also from the DataGridView which I am using).
Following your hint using the DataReader i searched the web for further clues and i came around a page that fills a DataTable (by DataTable.Load(DataReader)) but that's not what I want (coz it takes ages to load)
Can you tell me how to do it without the unavailable DataBind() method?
Thanks,
Wouter
|
|
|
|
|
Wouter Van Ranst wrote: it seems the .DataBind() method has disappeared from the DataGrid
Is this ASP.NET?
|
|
|
|
|
just normal C#
|
|
|
|
|
So Winforms? There never has been a DataBind in Winforms that is in ASP.NET. DataBind provides the timing mechanism required in a Web application. In a process based application you are always bound after initialization.
|
|
|
|
|
thanks for clearing this up, so how do i attach the DataReader to the DataGridView, the code in the article doesn't work without the DataBind() method (nothing is displayed in the DataGridView)
|
|
|
|
|
I have not used a DataReader but the DataGridView.DataSource property is how you bind it to data.
|
|
|
|