I have a main form in a panel on the left thats clickable, depending on what you click a new type of form opens. on the righti have another panel where i want to dock the forms that have been opened from clicking on the left.
How can i get the forms to add in a list under one another in the panel on the right? the issue with the code below is that it adds the first element fine. However when i add the second element they both dissapear behind the panel :/
private void addToPanel2(Form o)
{
if (o is Form)
{
if (panel2.Controls.Count == 0)
{
o.MdiParent = this;
panel2.Controls.Add(o);
o.Dock = DockStyle.Top;
o.Show();
}
else
{
//then we know that this is an addable data item
foreach (Form obj in panel2.Controls)
{
if(obj.GetType().Name.Equals(o.GetType().Name))
{
//we dont want to add it as the data type is already open
MessageBox.Show("This data item must already be open. Please Check.");
}
else
{
// add it as its not in there
Form f = (Form)obj;
f.MdiParent = this;
f.Dock = DockStyle.Top;
f.Show();
}
}
}
}
thanks
This is not possible, an MDI child form cannot be a child control of a panel. Adding a non-MDI form to a panel is an iffy proposition as well but is supported. Call its SetTopLevel() method, passing false, set its Visible property to true. You also have to set its FormBorderStyle property to None, it no longer behaves properly as a top-level window.
This just turns it into a UserControl. You are better off actually making it a UserControl, that uses a lot less resources and is much better documented.
Related
I have created ribbon form (XtraMain)and I set IsMdiContainer Property to true,i also add documentManager controle i set MdiParent to XtraMain I have add this code to open child forms
public void ViewChildForm(XtraForm _form)
{
if (!IsFormActived(_form))
{
_form.MdiParent = this;
_form.Show();
}
}
private bool IsFormActived(XtraForm form)
{
bool IsOpenend = false;
if (MdiChildren.Count() > 0)
{
foreach (var item in MdiChildren)
{
if (form.Name == item.Name)
{
tabbedView1.ActivateDocument(item);
IsOpenend = true;
}
}
}
return IsOpenend;
}
and i use this code in click of button to open the child form
private void bbtnEmployee_ItemClick(object sender, ItemClickEventArgs e)
{
FrmEmployee frme = new FrmEmployee();
frme.Name = "FrmEmployee";
ViewChildForm(frme);
}
my problem start when the form contain a LayoutControl for example i have this code that open on click of button
private void btnBonLivraison_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Top;
LookUpEdit OrderNumber = new LookUpEdit();
OrderNumber.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
OrderNumber.Properties.DataSource = shippProdu.GetOrderNumber();
OrderNumber.Properties.DisplayMember = "N° Bon de livraison";
OrderNumber.Properties.ValueMember = "N° Bon de livraison";
lc.AddItem(Resources.selectOrderNumber, OrderNumber).TextVisible = true;
lc.Height = 70;
this.Controls.Add(lc);
this.Dock = DockStyle.Top;
lc.BestFit();
the second I click on a button the tabHeader disappears,what cause this problem?and how can I solve it.before I use documentManager I used XtraTabControl and if i click a button to open LayoutControl and after that try to open another form the focus remaining in the first form even when the form two is already opened and if I want to go to form two I must first click on a tab of the first form and then click on tab of the second form , thanks in advance .
this is my main form
and this is when the eader disappears
If DocumentManager resides within the same form to which you add LayoutControl, it is the expected behavior. DocumentManager places a special documents' host onto the main form and set its Dock property to Fill. That is why it is incorrect to place LayoutControl onto the same form and dock it to form edges.
If you need to show tabbed documents and LayoutControl on the same form simultaneously, do not use the MDI mode. Consider the use of a separate UserControl. Place your DocumentManager there. Then, put this UserControl onto your form. Note that in this case UserControl's Dock property should be set to Top or Bottom since LayoutControl should fill all available area or vice versa.
I want to get form which is open but hidden. I have tried by this. I get the form but in this case form show and hide within fraction of second. If I skip mfrm.Show(), I don't get MailSynchronize form in Application.OpenForms.
MailSynchronize mfrm = new MailSynchronize();
mfrm.Show();
mfrm.Hide();
I get form by following method.
foreach (Form f in Application.OpenForms) //it will return all the open forms
{
if (f.Name == "MailSynchronize")
{
mfrm = (MailSynchronize)f;
break;
}
}
Can anybody please suggest me how to get open form which is hidden by default and I can get in Application.OpenForms?
If I Hide a form, does it exist in Application.OpenForms?
No, unfortunately if you Hide a form, it will not be present in Application.OpenForms
So how can I open an invisible Form? Also I want it to exists in Application.OpenForms.
If you want to open an invisible Form, and you want it want it to exists in Application.OpenForms, you can use this code instead of simply Show():
var f = new MailSynchronize();
f.Opacity = 0;
f.ShowInTaskbar = false;
f.Show();
How to find that form again?
To get the open instance of form you can use Application.OfType<MailSynchronize>()
var f= Application.OpenForms.OfType<MailSynchronize>()
.FirstOrDefault();
When I found it, How to show it again?
f.Opacity = 1;
f.ShowInTaskbar = true;
f.Show();
How to hide it again?
You should not call Hide() to hide the form because it makes the form to get out of Application.OpenForms, instead you should use this way:
f.Opacity = 0;
f.ShowInTaskbar = false;
Is there another way?
Yes, for example you can create an static property in a class, for example in Program.cs this way:
public static MailSynchronize MailSynchronizeInstance { get; set; }
and the first time you want to open your form, you can assign the instance to this property, and then you can use it using Program.MailSynchronizeInstance to show or hide and you don't need to look in Application.OpenForms or perform a workaround.
Also you can make this property in a singletone way.
EDIT
This should work for your specific case now:
this.Opacity = 0;
this.ShowInTaskbar = false;
When you add these 2 codelines in your MailSynchronize constructor the form will start minimized but will not show in your taskbar, which is essentially the effect you were looking for. Also the form will now popup in your Application.OpenForms Collection.
When form initiallize.
MailSynchronize mfrm = new MailSynchronize();
mfrm.Opacity = 0;
mfrm.Show();
mfrm.Hide();
How to find that form again?
foreach (Form f in Application.OpenForms) //it will return all the open forms
{
if (f.Name == "MailSynchronize")
{
mfrm = (MailSynchronize)f;
break;
}
}
When I found it, How to show it again?
mfrm.Opacity = 1;
mfrm.Show();
Hide again by Button.
mfrm.Hide(); //It will not show form in Application.OpenForms if I hide again by mfrm.Opacity = 0;
use f.Visible (return type is bool)
if it returns false, it means form is hidden. If it returns true then form is visible.
This is simplest possible thing, but I cant update text on status bar. I just started working in c# but cannot find solution. I tried below code:
Mdiparent
public void StutasText(string text)
{
toolStripStatusLabel.Text = text;
}
Child form
MDIParent1 obj = new MDIParent1();
obj.StutasText("Hello world");
obj.Refresh();
Its not showing status text in the status bar.
Where did I go wrong?
In the MDI Parent form, I assume you have toolStripStatusLabel1. If you dont have, you can add this by clicking on the little black arrow in the menuStrip control.
Option 1
In your MDI Parent (let's assume, frmMain is the MDI Parent form) form where you have the StatusStrip, goto frmMain.Designer.cs file and find the place
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
make this,
public System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
Then from your child pages you can access like below.
ToolStripStatusLabel statusStrip=((frmMain)(frmMdiChild.MdiParent)).toolStripStatusLabel1
Option 2
Declare a public property which will return the toolStripStatusLabel1 control or method where you can set the text property of the toolStripStatusLabel1 in the MDI Parent form. If you return the menuStrip1 itself then you have access to all the properties of that control. If you declare a method, which will set the text property of the toolStripStatusLabel1 then you can only set the text. Decide on what you want, based upon your requirement.
An implementation which returns the menuStrip1 control.
public ToolStripStatusLabel GetStatusBar
{
get
{
return this.toolStripStatusLabel1;
}
}
then from your child pages, you can use,
ToolStripStatusLabel statusStrip=((frmMain)(frmMdiChild.MdiParent)).GetStatusBar;
Option 3
To make it little bit more prettier, you can declare a method in a common class. Then you can reuse this in other child forms.
public void ShowStatusbarMessage(Form frmMdiChild, string message, NotifierType notificationType)
{
ToolStripStatusLabel statusStrip=((frmMain)(frmMdiChild.MdiParent)).GetStatusBar;
statusStrip.Text = message;
if (notificationType == NotifierType.SuccessInfo)
{
statusStrip.ForeColor = System.Drawing.Color.Green;
}
else if (notificationType == NotifierType.Warning)
{
statusStrip.ForeColor = System.Drawing.Color.Orange;
}
else
{
statusStrip.ForeColor = System.Drawing.Color.Red;
}
}
Here, NotifierType is an enum
((mdiMain)MdiParent).toolStripStatusLabel.Text = "My Text";
//but you must change the modifier property of toolStripStatusLabel to public etc
You're creating a new instance of MDIParent1, not using the instance that is shown/the instance your child form belongs to.
You could try using
this.MdiParent
instead of
new MDIParent1()
((frmMDI)this.MdiParent).yourcontrol.yourproperty=yourvalue;
frmMDI is unique name of MDI form.
First
In "mdi parent name".Designer.cs, change the type or member private to public
Second In your code add the next code
(("mdi parent name")MdiParent).toolStripStatusLabel.Text = "your text";
I'm facing the fact that i cannot understand Well how AdornerLayer is added for UIElements.
I have such a situation:
I have a WPF Form which is built with 3 controls:
A Grid on which are 1 Button and 1 TextBox.
In my System, when I click to open this Form, all 3 elements have AdornerLayer not null .
var controls = _frameworkElementProvider.GetUIElements(Content);
var controlsWithAddorner = new List<FrameworkElement>();
foreach (var control in controls) {
var adornerLayer = AdornerLayer.GetAdornerLayer(control);
if (adornerLayer != null) {
controlsWithAddorner.Add(control);
}
}
The collection controlsWithAddorner contains all my 3 controls.
The method GetUIElements(FrameworkElement parent) returns an IEnumerable<FrameworkElement> in which are all controls within a Panel.
I have such a functionality:
Refresh Form Designer. Which recreates the xaml for that Form.
After that Refresh is done, I check the list of controls for AdornerLayer. For all controls the AdornerLayer is null.
The problem is here, I cannot understand where AdornerLayer (s) are lost?
Should I take care To add them forr each UIElement when I Refresh the Designer of the Form?
Please advice me with some suggestions.
Thank you!
EDIT:
I'll show all the solution if other will encounter such problems :)
The mission is: When there is a SelectedControl in designer, keep it selected even a RefreshDesigner is done.
RefreshDesigner functionality recreates the xaml for the whole form.
// Refresh the Designer
private void RefreshDesigner() {
Content = _xamlProvider.ParseXaml(_xaml.ToString());
//Here was the Problem. All visual child elements of the Content wa not updated after xaml recreation.
//By including that call -> solved the problem
Content.UpdateLayout();
}
Firstly: The xaml of the Form is Updated by using the ParseXaml() method from XamlProvider
// in XamlProvider class
public Panel ParseXaml(string xaml) {
var regex = new Regex("<Grid ");
const int first = 1;
xaml = Regex.Replace(xaml, #"xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""", string.Empty);
xaml = Regex.Replace(xaml, #"xml:space=""preserve""", string.Empty);
//...
xaml = Regex.Replace(xaml, "<BindingGroup .*/>", string.Empty);
var content = (Panel)XamlReader.Parse(xaml);
return content;
}
Secondly: Content.UpdateLayout();
Ensures that all visual child elements of this element are properly updated for layout.
MSDN Official source
After that, All elements have AdornelLayer not Null and I'm able to set the Adorner Border for preciosly selected control in designer.
After the Form is Refreshed, call Content.UpdateLayout(); to Ensures that all visual child elements of the Content were properly updated for layout. MSDN official
We have a form which displays media items in tab pages of a tab control, and I'm implementing a feature which allows users to 'pop out' the tab pages into their own forms.
However, when I add the media player to a form rather than a TabPage, the background switches from the gradient fill of a tab page to the plain SystemColors.Control background of the parent form. I need to add the the media player to a control which has the same background as a TabControl, but which doesn't display a tab at the top. I tried adding the media player to the TabControl's control collection, but that just throws an exception.
How do I get a control which looks like a TabControl with no tabs? Should I keep trying to add the media player to a TabControl, or should I try to write a Panel with a custom-drawn background? If the latter, how do I make sure that works with all possible themes?
The questions seems to be about the UseVisbleBackgroundStyle. AFAIK only buttons and TabPages have this property.
The following is a very dirty hack, just to get you started:
1) derive a customControl from Panel and add "using System.Windows.Forms.VisualStyles;"
2) Add the following code
//warning: incomplete, add error checking etc
private readonly VisualStyleElement element = VisualStyleElement.Tab.Body.Normal;
public bool UseVisbleBackgroundStyle { get; set; }
protected override void OnPaint(PaintEventArgs pe)
{
if (UseVisbleBackgroundStyle)
{
var x = new VisualStyleRenderer(element);
x.DrawBackground(pe.Graphics, this.ClientRectangle);
}
else
{
base.OnPaint(pe);
}
}
Thanks to Henk - I eventually went with:
protected override void OnPaintBackground(PaintEventArgs e)
{
if (TabRenderer.IsSupported && Application.RenderWithVisualStyles)
{
TabRenderer.DrawTabPage(pe.Graphics, this.ClientRectangle);
}
else
{
base.OnPaintBackground(pe);
ControlPaint.DrawBorder3D(pe.Graphics, this.ClientRectangle, Border3DStyle.Raised);
}
}
Try creating your own customer UserControl
This answer is modified from another answer site. It does the trick rather cleanly.
In the load event for the window containing the tab control, try:
// TabControl is the name of the tab control in this window.
TabControl.Appearance = TabAppearance.FlatButtons;
TabControl.Multiline = false;
TabControl.SizeMode = TabSizeMode.Fixed;
TabControl.ItemSize = new Size(0,1);
// The tabs are now gone. Select the panel you want to display
TabControl.SelectTab("InProgressTab");