Moving image dynamically when user resizes window - c#

I'm going to be short and sweet with only needed information. I'm making an application which has multiple forms displayed in a MDI parent.
I want my users to be able to resize this window and the things i place inside each form resize and move when they resize the window. I do not know how to do this. When i anchor the picture box containing my image to the sides of the form i'm assuming it would work but when you run the application you are not resizing the form, you are resizing the MDIparent form which does not affect the image.
Help.
Edit: removed useless code.
MDIparent code:
private void ribbonButton1_Click(object sender, EventArgs e)
{
foreach (Form f in this.MdiChildren)
{
if (f.GetType() == typeof(Form2))
{
f.Activate();
return;
}
}
Form form2 = new Form2();
form2.MdiParent = this;
form2.Show();
}
Form2 that is the MDICHILD:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.ControlBox = false;
this.WindowState = FormWindowState.Maximized;
this.BringToFront();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}

When the MDI parent is resized, the child form sizes of the MDI will not be affected. You will need to do this manually. So, anchoring is the right solution to the child form. Then you will need to set the sizes of the children manually on the resize event of the parent, according to the parent's size. This is all I can say because your post is not clear. Maybe some screenshots could help.

Related

Resize a locked form programmatically?

I have a form acting as a sidebar, that will always be locked in position, and width. However, if I were to resize the MDI Container, this form should also grow to fit the Parent form length-ways.
For example, if I were to use a method in the Parent form like so:
private void ParentForm_SizeChanged(object sender, EventArgs e)
{
FormWindowState LastWindowState = FormWindowState.Normal;
if (this.WindowState != LastWindowState)
{
if (this.WindowState == FormWindowState.Maximized)
ResizeChildForm(this);
}
}
And then in the Child form, if I have the property Locked = true; will I have to disable that, resize the form, then enable that again? I.e.
private void ResizeChildForm(ParentForm)
{
this.Locked = false;
//resize form
this.Locked = true;
}
Or can I just change the size of the form without having to change that property?
To answer your question,
can I just change the size of the form without having to change that property?
Yes you can, see this link for more details.
Note from the article :
Locking controls prevents them from being dragged to a new size or location on the design surface. However, you can still change the size or location of controls by means of the Properties window or in code.

Panel Could not set Visible True in MDI

I am using C#. Net Windows application.
I have one MDI parent form and many child forms. I put panel in MDI parent form and drag several button inside panel.
When I click the button they open another child form and set visible false to panel
like this (sample code):
private void Button_Click(object sender, EventArgs e)
{
panel1.Visible = false;
ChildForm Form2 = new ChildForm();
Form2.WindowState = FormWindowState.Maximized;
Form2.Show();
}
Now they perfectly working. What the problem is, when I close the child form the panel could not visible in MDI parent form. Its always panel visible false. I set to true., see my code.
private void ChildForm _FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
MDI md = new MDI();
md.panel1.Visible = true;
}
am also using BringToFront, SendToBack. No use. Please assist.
The problems are:
you create a new instance of MDI form in your child form with MDI md = new MDI();
You should instead retrieve the instance of the opened MDI and set md.panel1.Visible =
true; on this instance. You can use the MdiParent property.
MDI md = (MDI)this.MdiParent;
md.panel1.Visible = true;
and you call This.Dispose before your the code that set panel visible. I am not sure that the code which is after This.Dispose will be executed...
hi friends i Solved this and i got worked now...
here the Solution..
> private void ChildForm_FormClosed(object sender,FormClosedEventArgs e)
> {
> MDI md = (MDI)this.MdiParent;
> md.panel1.Visible = true;
> }

how to exclude control from a WinForm.Opacity in C#

I have a form that i set it's Opacity as 50% like this:
this.Opacity = 0.5D; <--this==Form
My problem is that everything that on the form is with an Opacity of 50%
I have two buttons on the form and I want them without Opacity.
I know that this.Opacity included all Controls and for some reason the graphics too
My question is, How to Exclude the Opacity of the controls?
Example Image:
Thanks!
Since Control doesn't have Opacity property and plus that, most of the controls doesn't support transparent colors, then a working solution can be this:
Create a Form called MainForm and place all the controls you're going to be excluded.
1.1 Set both of BackColor and TransparencyKey properties of MainForm to the same color, e.g Color.Red
Create another form named TransparentForm and place all controls that must become transparent. Set ShowInTaskbar property to False.
In the MainForm Load event show the TransparentForm and send it to back.
private void MainForm_Load(object sender, EventArgs e)
{
TransparentForm form = new TransparentForm();
form.Opacity = 0.5D;
form.Show();
form.SendToBack();
}
The position of controls in both form must be such that, when combined, it shows the proper user interface.
Crate a C# project and add 3 forms named
MAIN
BACKGOUND
Child
and add the following code for "MAIN" form load event;
private void MAIN_Load(object sender, EventArgs e)
{
Child frm1 = new Child();
BACKGOUND frm2 = new BACKGOUND();
frm2 .WindowState = System.Windows.Forms.FormWindowState.Maximized;
frm2.Opacity = 0.5;
frm2.Show();
frm1.ShowDialog();
frm2.Close();
}

Can I load a new form into panel?

I am working on Windows Application.I am having a menustrip in one form and I want to ask that, can I have a panel which will load new form on particular click of menustripitem.
Ex:
File Data
ABC Hello
XYZ Bye
These is my menu bar.On click of ABC I dont want to go on different form can I do something
(whatever I want to)on the same form using panel.
Thanks
I think that I had the same question.
But I found the answer for it
CodeProject Example
First you have to configurate the Form:
myForm.FormBorderStyle = FormBorderStyle.None;
And then, manipulates the action:
Form1 myForm = new Form1();
myForm.TopLevel = false;
myForm.AutoScroll = true;
frmMain.Panel2.Controls.Add(myForm);
myForm.Show();
Hope to help you. Hugs :D
You can use MDI Form.
Try something like this
//Create a new instance of the MDI child template form
Form2 child= new Form2();
//Set parent form for the child window
child.MdiParent=this;
//Display the child window
child.Show()
you can also refer to this site.
If you put the whole content of the target form into a UserControl, you can add a panel to your main form and place the UserControl on that panel.
You still have option to display a separate form by creating an empty form and placing the same UserControl on that form, too.
As Int3 ὰ already points out, you could use MDI forms instead. However, if you want to use dockable panels, the UserControl would be the way to go.
Add two panels on your form, only one will be visible at the same time. Then, add two events on your menus:
private void ABCToolStripMenuItem_Click(object sender, EventArgs e) {
panelABC.Visible = true;
panelXYZ.Visible = false;
}
private void XYZToolStripMenuItem_Click(object sender, EventArgs e) {
panelABC.Visible = false;
panelXYZ.Visible = true;
}
private void pbxpurchase_Click(object sender, EventArgs e)
{
contentpnl.Controls.Clear();//contentpnl is the panelname
purchasebook purchasebk = new purchasebook();//purchasebook is a formname
purchasebk.TopLevel = false;
purchasebk.AutoScroll = true;
contentpnl.Controls.Add(purchasebk);
purchasebk.Dock = DockStyle.Fill;
purchasebk.Show();
}
try this 100% tested

how to show a child form in MDI container without the apperance of the controls in the Container Form in the Child Form?

in my project in the container form i use buttons to open the child forms , not Strip Menu but the buttons in the container always appears on the child form
how to privet the buttons or any other controls form being above the child form
i am using Visual Studio 2008 professional edition C# programming language
as in this Image the button suppose to be in form1 and not to be seen in Form2 (Child)
and also the other controls in the Container
sir i have best solution for
create new empty form and than set following property of this form
set in Form_load event
private void bg_Load(object sender, EventArgs e)
{
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
than after
write following code in mdi form load event
private void Main_Load(object sender, EventArgs e)
{
bg bg = new bg(); // create object of empty form my empty form name is "bg"
bg.MdiParent = this;
bg.Show();
}
what ever you want in background add into empty form....]
Enjoy
You should use ToolStrip or MenuStrip to call your child form. In your case, I assume you just drag and drop a Button into your Form1. That's why the button is floating.
But if you are persistent and still don't want to use ToolStrip and MenuStrip, you can hide the button after showing the childform.. Ex:
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent = form1;
f2.Show();
button1.Visible = false; // This will cause your button to be hidden.
}

Categories

Resources