|
Hi
I want to create controls dynamically in the form
Initially i have textbox1 besides this button1 (text as Plus)
when i click on plus button it has to create textbox2,button2(plus) and also button3(minus) .
e.g: whenever i click on button3(minus) it shouls collapse(remove textbox2,button2,button3) and so on but move all the below controls to top position .............. in this manner i want to add and remove controls .
thanks in advance...
|
|
|
|
|
Sounds like homework. And it's not very difficult; look through the auto-generated code from another form for hints.
|
|
|
|
|
You can move controls around on the form dynamically by setting their Control.Left and their Control.Top properties. As for creating new ones, it's also pretty simple, just create them in code, add them to the parent form then set their top and left Properties
TextBox t = new TextBox();
form1.Controls.Add(t);
t.Top = 10;
t.Left = 10;
that should do it.
|
|
|
|
|
1. Create a user control that has Button and TextBox in it.
2. Add a FlowLayoutPanel to your form and set its FlowDirection as TopDown .
3. Handle the button click event of the button in the Form itself (through delegate). And then add and remove controls at your will. They will move up/down automatically.
|
|
|
|
|
Hello,
How can i convert txt file to excell file?
The data in the file is seperated be spaces or tabs.
I know i can do it using copy-->paste but i need to write a program for the conversion
|
|
|
|
|
You can read the file through StreamReader and then write to the excel file.
|
|
|
|
|
ok but how do i seperate the data seperated by spaces or tabs in the text file to different cells in the excell file?
|
|
|
|
|
If it is tab, text would automatically be divided into cells. If it is space, you can replace them with tabs.
|
|
|
|
|
how do i replace space with tab? how do i write in the code to insert tab in a line?
|
|
|
|
|
greetings. i have an issue with the following code. for some reason whenever it is executed it is consuming around 60% of the CPU. this is strange, and was wondering if you had any comments?
private void HomeTableLayoutPanel_MouseMove(object sender, MouseEventArgs e)
{
PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location));
TableLayoutPanelCellPosition HomeCurrentPosition = new TableLayoutPanelCellPosition(-1, -1);
if (HomeCurrentPicBox != null)
{
HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row.ToString());
}
}
thank you for your time.
|
|
|
|
|
This is happening beause the method is being called 100s of times when moving the mouse in one "jesture" over a significant distance. Put a breakpoint on and you'll see what I mean, the method is called almost per pixel moved. Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
1. During adding every PictureBox, add an eventhandler for MouseEnter and Leave. This will remove the need for GetChildAtPoint.
similarly, find some other places where refactoring could help you avoid repetative control
|
|
|
|
|
i hear what you are saying but that means i have to do it 200 times! ie th number of pictureboxes im using.
im trying to code it short by using table methods.
|
|
|
|
|
My Dear,
you must have added these controls inside tablelayoutpanel through code only... right? during adding it, you can add an eventhandler. So, this will be done only once... Its easier than you assume.
Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong.
Som
|
|
|
|
|
i get what you are saying now. had not thought of it like that.
make all the picturebox share only one method upon event? right?
|
|
|
|
|
Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong.
thats the reason im looking into this! i thought i had to issue 100/200 separate picture box events. but i can make them share just the one!
thanks for bringing this to attention once again.
|
|
|
|
|
good we all need a piece of advice once in a while... does wonders 
|
|
|
|
|
Hi,
I would like to draw onto a Windows form constantly, without freezing it.
I know it is possible, but how?
Thanks in advance.
|
|
|
|
|
Application.DoEvents() is probably what you're after. What sort of drawing are you doing continuously?Regards,
Rob Philpott.
|
|
|
|
|
I've thought about Application.DoEvents() but some say that it is not a safe solution. I think I can summarize what I am doing as creating random bitmaps until it is identical to another bitmap.
I know the concept is meaningless, but it is just a test which is leading to familiarizing myself with the idea of drawing onto Windows forms. 
|
|
|
|
|
Create timer and every tick event is fired call Invalidate() method
|
|
|
|
|
I've tried it but the form is still freezing and I've no control over it.
Here is the code I have in my OnPaint method.
protected override void OnPaint(PaintEventArgs e)
{
if (session == 0)
{
Graphics dc = e.Graphics;
Pen CyanPen = new Pen(Color.Cyan, 1);
Pen MagentaPen = new Pen(Color.Magenta, 1);
Pen YellowPen = new Pen(Color.Yellow, 1);
Pen BlackPen = new Pen(Color.Black, 1);
Random rnd = new Random();
int buff = 0;
for (int y = 0; y < 300; y++)
{
for (int x = 0; x < 300; x++)
{
buff = rnd.Next(0, 4);
if (buff == 0)
dc.DrawRectangle(CyanPen, x, y, 1, 1);
if (buff == 1)
dc.DrawRectangle(MagentaPen, x, y, 1, 1);
if (buff == 2)
dc.DrawRectangle(YellowPen, x, y, 1, 1);
if (buff == 3)
dc.DrawRectangle(BlackPen, x, y, 1, 1);
}
}
session++;
}
}
|
|
|
|
|
That's a lot of drawing 300 by 300 => 90000 rectagles in one session
Try putting a a this.Invalidate inside the first for and out of the second/inner for.
|
|
|
|
|
I tried your advise and still, I can't do anything on the form until the drawing is over.
|
|
|
|
|
I just realized that my first reply or message is a total ...
My bad.
All of the drawing is inside the OnPaint()!!!!
Use the fors outside the OnPaint() or better said call the paint or invalidate method
FROM the fors.
|
|
|
|