Beginner questions

  • Thread starter Thread starter Peter Morris
  • Start date Start date
P

Peter Morris

1. What is the advantage of puting some controls on a panel control
instead
of directly on the form?

What is the benefit of putting toys in a box? It makes them easier to move.

2. When I set backgroundcolor and backgroundimage to certain values (to
certain color and certain image, respectively of a form) and run it, I see
the background color but can't see the backgroundimage. How do I cause it
to
show-up?

Not sure but I suspect it's one or the other maybe?

3. I want to choose some kind of control (like picturebox or similar) in
order to display different view in different times, i.e images, real-time
video(with directx) etc.
It should support most of the methods for that.
Can someone recommend what is the most suitable?

If you are just starting out and asking questions like "why put controls in
a panel" I would recommend you start off with writing very small programs
with little or no functionality. You certainly shouldn't be trying to play
videos etc. If you *really* want to play videos and so on then use WPF in
..NET 3.5 and not WinForms. For WPF I would strongly suggest you buy a book!


Pete
 
I'm a beginner in dotnet and I'd like to ask a few questions-
1. What is the advantage of puting some controls on a panel control instead
of directly on the form?
2. When I set backgroundcolor and backgroundimage to certain values (to
certain color and certain image, respectively of a form) and run it, I see
the background color but can't see the backgroundimage. How do I cause it to
show-up?
3. I want to choose some kind of control (like picturebox or similar) in
order to display different view in different times, i.e images, real-time
video(with directx) etc.
It should support most of the methods for that.
Can someone recommend what is the most suitable?

Regards

Rami
 
Hi Rami,

Rami said:
I'm a beginner in dotnet and I'd like to ask a few questions-
1. What is the advantage of puting some controls on a panel control instead
of directly on the form?

If you put groups of controls on separate panels, groupboxes or other
container controls you can easily rearrange your layout by moving, anchoring,
or docking the container controls. If you intend to use only one container
control, you can just put the controls directly onto the form, but large
scale applications use a whole range of container controls, very much like a
news paper or magazine layout. You don't arrange individual words in a
newspaper designer, but whole articles.

2. When I set backgroundcolor and backgroundimage to certain values (to
certain color and certain image, respectively of a form) and run it, I see
the background color but can't see the backgroundimage. How do I cause it to
show-up?

That depens on what kind of control you are using. Some controls may ignore
the BackgroundImage property. Panel for instance can easily display a
background using this code

panel1.BackgroundImage = Image.FromFile(@"C:\image.png");

PS, this way of doing it will also lock the image file when the program is
running. If you plan on using images, consider loading them as a resource.

3. I want to choose some kind of control (like picturebox or similar) in
order to display different view in different times, i.e images, real-time
video(with directx) etc.
It should support most of the methods for that.
Can someone recommend what is the most suitable?

There are no control that will do this automatically. You can use a
PictureBox AND a media player plugin control and hide the one not being used
or call BringToFront() on the control you want displayed if both the
PictureBox and media player are in the same place and of equal size. You
will need to write code to determine which of the controls should be used.
 
Thanks Mr. Wennevik ,
I would like the control to track dynamically the form dimensions, i.e if
the forms size is modified the control should also, and with the same
values.
Is it possible and how?

regards
Rami
 
Rami said:
Thanks Mr. Wennevik ,
I would like the control to track dynamically the form dimensions, i.e if
the forms size is modified the control should also, and with the same
values.
Is it possible and how?

regards
Rami

There are two ways to do this (other than hardcoding it).

If the Control is the only thing on the form you can simply set its Dock
property to DockStyle.Fill. It should then expand to fill the entire form
and resize with the Form.

If you don't want it to take all the space but still want to resize you can
adjust the position so that it looks right on the designer and then set the
Anchor property to both Left and Right, and/or both Up and Down as you
prefer. It will then also resize.

Another option which is what you usually do larger scale operations is use
panels/groupboxes etc to stake out part of form. The panels/groupboxes need
to be docked correctly to adjust with the form size, and the PictureBox/media
player can be Docked to Fill inside one of the panels/groupboxes ...

A sample on how this is done. Run this code on a winform (for instance in
its constructor):

Panel p1 = new Panel();
p1.BackColor = Color.Red;
Panel p2 = new Panel();
p2.BackColor = Color.Green;
Panel p3 = new Panel();
p3.BackColor = Color.Blue;

TextBox tb = new TextBox();
tb.Multiline = true;
tb.Dock = DockStyle.Fill;

Controls.Add(p3);
Controls.Add(p2);
Controls.Add(p1);

p1.Controls.Add(new TextBox());
p2.Controls.Add(new TextBox());
p3.Controls.Add(tb);

p1.Dock = DockStyle.Bottom;
p2.Dock = DockStyle.Left;
p3.Dock = DockStyle.Fill;


One important thing to remember when working with docking is the order you
add docked controls will determine how docking is done. By adding filled
panel p3 first the next two panels will push the filled panel to make room
for themselves. By adding p2 before p1 the lower panel will take the entire
space at the bottom while p2 will be adjusted upwards to make room for p1.
Try experimenting with the order the controls are added.
 
Back
Top