|
You can't. Or rather, you can, but it'll make the code even more complicated. A switch case tests the switch statement and provides multiple paths of execution. Yours only has two - true and false.
Incidentally, if that's related to the code you last posted, your design is a little off. Sending commands in plain text over a stream isn't the best way to go about remote-controlling a computer.
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Okay thank you!
then i will make it with if!
|
|
|
|
|
If I may question your logic for a second ...
If get_Split is an array of strings why not
System.Diagnostics.Process.Start("shutdown", "-s -t " + get_Split[1]);
?
The parse to int and then converting to string seems a little silly in context.
|
|
|
|
|
|
How to store and retrieve ZIP files from oracle 10g. ZIP files consist of heavy satellite images.
Thanks in advance.....!!
|
|
|
|
|
You shoud better store them as blobs.Oracle blobs could store to 4 GB binary objects but you need to provide for storing and retrieving on your own.
Life is a stage and we are all actors!
|
|
|
|
|
I try to draw line with this code on a panel (I sent code only related to drawing). I can draw one line but if I want to draw multi line, there is an error like this: ArrgumentException was unhandled, Parameter is not valid.
Where is my fault?
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (drawLine == true)
{
PictureBox PictureBox2 = new PictureBox();
int x1 = panel1.Width / 2;
int y1 = panel1.Height / 2;
PictureBox2.Location = new Point(x1, y1);
PictureBox2.Size = new System.Drawing.Size(50, 30);
PictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
panel1.Controls.Add(PictureBox2);
PictureBox2.Image = Image.FromFile(@"C:\warehouse.bmp");
for (int i = 0; i < MaxRows; i++)
{
PictureBox PictureBox1 = new PictureBox();
PictureBox1.Image = Image.FromFile(@"C:\retailer.bmp");
int x = coordinates[i, 0];
int y = coordinates[i, 1];
PictureBox1.Size = new System.Drawing.Size(25, 25);
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
PictureBox1.Location = new Point(x1 + x, y1 - y);
panel1.Controls.Add(PictureBox1);
Graphics g = e.Graphics;
Pen myPen = new Pen(Color.Black, 1);
g.DrawLine(myPen, x1, y1, x1+x, y1-y);
myPen.Dispose();
g.Dispose();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
TakeValues();
drawLine = true;
panel1.Invalidate();
}
|
|
|
|
|
There are several problems with the code that you have posted.
1) you should be aware that panel1_Paint happens every time that something happens to your form, which can be several times a second.
2) because of 1) you are creating two new PictureBoxes (PictureBox2 and PictureBox1) several times a second. This will make your code very, very slow if MaxRows is a large number. Since PictureBox2 is always in the same place, always the same size and always contains the same image why not create it once in the Form.Load() event handler, or better than that in the designer. If you are worried about it being in the correct place when your Form is resized, use the Anchor property.
The parameter not valid refers to the Graphics object(g). Delete the g.Dispose() entirely. YOU DIDN'T CREATE IT, THEREFORE YOU MUSTN'T DISPOSE IT.
You could also move the Pen myPen = new Pen(Color.Black, 1); outside the for loop, put it on the line above the for statement, and move the myPen.Dispose() call to after the closing brace of the for loop. No need to create it and then destroy it each time through the loop. Create it before the loop starts, then destroy it after the loop completes.
[Edit]
I have just realized that the problems with your code are worse than I noticed after my first brief reading of it.
this section of code, from inside the for loop:
PictureBox PictureBox1 = new PictureBox();
PictureBox1.Image = Image.FromFile(@"C:\retailer.bmp");
...........
...........
...........
...........
PictureBox1.Location = new Point(x1 + x, y1 - y);
panel1.Controls.Add(PictureBox1);
means that the first time your Form is painted (assuming that MaxRows is 10, just for discussiion), there will be 11 PictureBox es in panel1. The next time it is painted there will be 22 PictureBox es stacked 2 deep in the same locations, the next time 33 PictureBox es and so on. All stacked one on top of the other. You can mitigate this partly by turning off drawLine as the last statement of the:
if (drawLine == true)
{
PictureBox PictureBox2 = new PictureBox();
int x1 = panel1.Width / 2;
int y1 = panel1.Height / 2;
PictureBox2.Location = new Point(x1, y1);
PictureBox2.Size = new System.Drawing.Size(50, 30);
PictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
panel1.Controls.Add(PictureBox2);
PictureBox2.Image = Image.FromFile(@"C:\warehouse.bmp");
Pen myPen = new Pen(Color.Black, 1);
for (int i = 0; i < MaxRows; i++)
{
PictureBox PictureBox1 = new PictureBox();
PictureBox1.Image = Image.FromFile(@"C:\retailer.bmp");
int x = coordinates[i, 0];
int y = coordinates[i, 1];
PictureBox1.Size = new System.Drawing.Size(25, 25);
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
PictureBox1.Location = new Point(x1 + x, y1 - y);
panel1.Controls.Add(PictureBox1);
Graphics g = e.Graphics;
g.DrawLine(myPen, x1, y1, x1+x, y1-y);
}
myPen.Dispose();
drawLine = false; <==================== NEW CODE
}
but that won't stop them multiplying each time the button is clicked. You would be far better drawing the images directly onto panel1 , as you do with the lines, unless there is a special reason for using a PictureBox .
[/Edit]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
modified on Friday, August 21, 2009 3:45 PM
|
|
|
|
|
Thanks for your help. I started programing only one month ago. I have done many mistake like this. But I try to learn.
Thanks again.
I checked your code. Really I want to thanks you again. I will draw the images without using picturebox. However, My problem still go on. Yes, all lines is drawn after button click, but If I minimize the form and maximize again, all lines disappear. Do you have any idea about it? How can I solve this problem?
modified on Friday, August 21, 2009 4:42 PM
|
|
|
|
|
mgroses wrote: If I minimize the form and maximize again, all lines disappear. Do you have any idea about it? How can I solve this problem
This is because in the panel1_Paint event handler you only draw the lines if drawLine is true. When the Panel is resized drawLine is still false. One way to solve this is to handle the Form.Resize event like this:
private void Form1_Resize(object sender, EventArgs e)
{
drawLine = true;
}
but really this is just patching one hole at a time. Get another program running at the same time as your application. Make sure that its window is not maximised and then move it so that it partly covers the images and lines in your application and then move it away. Are your lines redrawn? How are you going to cure that?
The problem is that the design of your program is wrong. You need to arrange things so that everything is drawn every time the panel repaints. There are too many ways of doing that to give them here. Why don't you have a think about it, have a go and come back if you have any problems.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
thnaks for your help.
This is not my real project. I changed my codes. I didn't use picturebox(I used drawimage function). and I have no problem about lines now. You are right I have to think about the design of the program. I try to do step by step. If I have any problem, I will contact.
|
|
|
|
|
As much i know that there is a method "protected void OnPaint(eventArgs e)" is a function that can be used for your problem.
try it!!
and let me know.
thanks
Mahbub-E-Rabbani [TAFIN]
|
|
|
|
|
Hello Everyone-
I have an imagelist that I have added .ico files into. The icons have multiple resolutions. I am trying to use one imagelist for multiple roles in my application. I set the default size to be 32,32. The places in the application where I set the image of the picturebox or a large button to an image in the imagelist, it works fine. But there are times when I want to only use a 16,16 icon, say in the treeview. When I set the icon of the node to the image in the imagelist, it is using the default size which is 32,32. I've tried setting the size on the fly of the imagelist, such as imageListStatus = new Size(16,16), but that appears to delete all of the images out of the list.
Is there any way to use multiple resolutions out of an imagelist that is containing icons with many sizes?
TIA!
|
|
|
|
|
My suggestion is, create 2 image list, one with 32x32 size and other with 16x16
|
|
|
|
|
Thank you very much! I was just making sure this was the "proper" way of doing things!
|
|
|
|
|
hi,
plz tell me How to insert the values in to two database tables in C#.
Thanks.
Himanshu
|
|
|
|
|
himanshu_roy81 wrote: How to insert the values in to two database tables in C#.
Technically, you do this with 2 SQL commands, not C#, but I get what you mean. Basically, you need to create two insert statements (make sure you use parameterized queries), and then you run them both in order - you can use one command object for this (use the ExecuteNonQuery method to perform it).
I haven't specified which of the command classes to use because you haven't specified which database you're hitting, i.e. if it's SQL Server, you'd use SqlCommand. (If both of the inserts have to be performed in one transaction, you'd wrap them up in a transaction).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You need to decide / specify which technology you want to use.
Check out the following:
ADO.NET
LINQ (to SQL or to Entities)
TableAdapters.
There are other, 3rd party ways to do this (e.g. Nhibernate). Which technology you choose is dependant upon your circumstances.
|
|
|
|
|
"INSERT INTO table1 ... <big>;</big> INSERT INTO table2 ... "
|
|
|
|
|
hello
I am having datagridview with columns
Description area rate and value.
All the columns are datagridview textbox columns.
the description column when clikced where we can enter the description
and when the columns area,rate and value are double clikced then the
page must redirect to another page.
I tried this by the event CellDoubleClick but i can't get what i required
Plz, help me in doing this.
|
|
|
|
|
Anjani Poornima wrote: I tried this by the event CellDoubleClick but i can't get what i required
What does this mean?
What do you get?
What have you tried?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hello,
I wrote the code for redirecting the page in celldoubleclick event.
It make me redirect the page when the column is doubleclicked.
But what i need is only when the column 'area' is doubleclicked it must
redirect the page.
Here i have to check the condition only when the column area is double
clicked it must redirect the page.
How to do this.What event i have to use.
Plz, help me in doing this.
|
|
|
|
|
There are two DoubleClick events for a cell CellDoubleClick , which you have already used, and CellContentDoubleClick . The DataGridView is very fussy about exactly where you click. If you double-click on the displayed value but are only handling the CellDoubleClick event, nothing happens. Conversely, if you double-click in the cell, but not on the displayed value and you are only handling the CellContentDoubleClick event, nothing happens then either.
Set up a handler method for both:
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("Content DoubleClick");
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("Cell DoubleClick");
}
and experiment with the placement of your double-clicks.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
What is your problem excactly?
If you don't know how to redirect, look here Response.Redirect()[^]
Anjani Poornima wrote: I tried this by the event CellDoubleClick but i can't get what i required
Did you get any good data from the event as in what cell contained or from witch row was it?
|
|
|
|
|
suppose i have one mdi form and two mdi child form. suppose i have save method in both the mdi child form and i just want to call the save method of active mdi child form from mdi parent form.please help with sample code.
thanks in advance
tbhattacharjee
|
|
|
|
|