bring to front not working winform c# my code - c#

i have telerik panel i want show to form in front but form not show bringtofront not working. i don't know why please check below image and code, i am clicking product button but product form show back side ;(
frmProductList objForm = new frmProductList();
pndocmain.DockControl(objForm, DockPosition.Fill, DockType.Document);
objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
objForm.TopMost = true;
objForm.BringToFront();
objForm.Show();

first thing, that I would try is show the form with owner. But I really don’t know, why you haven’t that in front even though you have TopMost as true.
frmProductList objForm = new frmProductList();
pndocmain.DockControl(objForm, DockPosition.Fill, DockType.Document);
objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//objForm.TopMost = true;
//objForm.BringToFront();
objForm.Show(this);

Related

Child form appearing underneath controls on parent form

I have a C#, .net, Windows Forms application. I have a form set as an MDI container on which I dynamically add buttons. Clicking a button opens a child form. However, the buttons I created appear on top of the child form instead of the child form appearing over (and covering) everything on the parent form. What am I doing wrong?
Here's how I add the buttons to the form:
Button btn1 = new Button();
btn1.BackColor = ColorTranslator.FromHtml("#456EA4");
btn1.Text = department.DepartmentName;
btn1.Location = new System.Drawing.Point(posX, posY);
btn1.Size = new System.Drawing.Size(sizeX, sizeY);
btn1.Font = new System.Drawing.Font("Calibri", 40F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
btn1.ForeColor = Color.WhiteSmoke;
btn1.TabStop = false;
this.Controls.Add(btn1);
Here's is where I open the child form:
frmToBuildFromSchedule frmToBuild = new frmToBuildFromSchedule(department);
frmToBuild.FormClosed += new FormClosedEventHandler(frmToBuildFromSchedule_FormClosed);
frmToBuild.MdiParent = this;
frmToBuild.Show();
Here is the result:
You are putting the buttons directly on the parent MDI form, which is not typical of an MDI style application. Instead, put the code that is currently in the click event of your buttons in a menu option or a ribbon button (those can also be dynamically created).
Alternatively, create a child form, maximize it, and place your buttons on that.
I think the answer by sam on the posted duplicate link is interesting. Rather than using MDI, set form.TopLevel = false; and add the form as a child control. I'm not sure if there are any downsides to this approach.
Form fff = new Form();
fff.Controls.Add(new Button { Text = "Button1" });
fff.Load += delegate {
Form ffff = new Form { TopLevel = false };
fff.Controls.Add(ffff);
ffff.Visible = true;
ffff.BringToFront();
};
Application.Run(fff);

How to reproduce a forum/twitter-like UI on Winform

As a classic forum, threads and replys are displayed on a page, with dark and light and dark and light backcolor.
I am trying to write a client of a forum on windows using winform. It is
At first, I have tried this way:
Add a big panel to the form, let's call it the PARENT PANEL.
Add small panels to the big panel like this:
panel1.Visible = false;
for (int i=0; i<5;i++)
{
Panel parent = new Panel();
parent.Height = 800;
Random ra = new Random();
TextBox p = new TextBox();
p.Text = "fehsuifq";
p.Multiline = true;
p.WordWrap = true;
p.Dock = DockStyle.Fill;
parent.BackColor = Color.FromArgb(ra.Next(0, 254), ra.Next(0, 254), ra.Next(0, 254));
p.BorderStyle = BorderStyle.None;
p.ReadOnly = true;
p.TabStop = false;
p.BackColor = this.BackColor;
parent.Controls.Add(p);
parent.Dock = DockStyle.Top;
panel1.Controls.Add(parent);
}
panel1.Visible = true;
Every panel(tenicially, a control) displays a thread's text and images and others details(like authors or avator).
Images are not shown until it is clicked.
when the image is clicked, it is loaded and the controls's height will change as result.
The PARENT PANEL will contains hundreds of these controls since there will be so many threads. It is and have to be scrollable, obviously.
But if I put a textbox in the control, the scroll wheel no longer work on the PARENT PANEL.If I use a label, it is not selectable.
I think this way can't be more stupid, completely.
So I am looking for a better to do this job, to display hundreds or even thousands threads/replys on winform, which is:
the height is dynamic, because the images inside will not load until it is clicked.
The text inside is selectable (I edited this just to disambiguate)
the PARENT PANEL can response to the mouse's wheel, just like twitter, forums.
So that I can use my scroll wheel to browse all the replys at one time. The loading is a background work.
Look at the picture, when the text is selected, the whole panel is still response to the wheel(just like normal webPage). This is a uwp app and I am not sure if winform can do this.

Set Location for new form

I use below code to make lightbox effect and it works as i expected. However if i move the parent form it still pop-ups on the center of the screen.
// Execute this code from parent form
Form f = new Form();
f.ShowInTaskbar = false;
f.BackColor = Color.Black;
f.Size = this.Size;
f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f.StartPosition = this.StartPosition;
f.Opacity = 0.6;
f.Show();
So i changed the above code like below;
f.StartPosition = FormStartPosition.CenterParent;
However it still doesn't pop-up center of the parent form.
Also i tried below, It didn't work too;
f.SetBounds(this.Location.X, this.Location.Y,this.Width, this.Height);
I already tried the solutions here;
Show a child form in the centre of Parent form in C#
They also didn't work.
What i want to do is, creating a second form with the same size and same location.
Just changing this line;
f.Show();
to this line, It worked;
f.ShowDialog();

Adding a CheckBox to WPF MessageBox

The Message Boxes of WPF could be customized as i understand.
I was wondering is it possible to add a CheckBox to the WPF MessageBox with say - Don't show this message again etc.?
Possible, you can change the WPF control styles and templates as per your requirement, see these links for further references:
Custom Message Box
http://blogsprajeesh.blogspot.com/2009/12/wpf-messagebox-custom-control.html
http://www.codeproject.com/Articles/201894/A-Customizable-WPF-MessageBox
http://www.codeproject.com/Articles/22511/WPF-Common-TaskDialog-for-Vista-and-XP
Could just use a Window
Passed checked in the ctor so you can get the value back
bool checked = false;
Window1 win1 = new Window1(ref input);
Nullable<bool> dialogResult = win1.ShowDialog();
System.Diagnostics.Debug.WriteLine(dialogResult.ToString());
System.Diagnostics.Debug.WriteLine(checked.ToString());
I realize this is a very old thread, but I was searching this matter today and was surprised to see no replies mentioning Ookii: https://github.com/ookii-dialogs/ookii-dialogs-wpf
I was already using it for Folder Browsing. Now I wanted to add a "Don't Show Again" checkbox whenever the main window is closed, and it's really simple to use it.
Here's my code:
using Ookii.Dialogs.Wpf;
//create instance of ookii dialog
TaskDialog dialog = new();
//create instance of buttons
TaskDialogButton butYes = new TaskDialogButton("Yes");
TaskDialogButton butNo = new TaskDialogButton("No");
TaskDialogButton butCancel = new TaskDialogButton("Cancel");
//checkbox
dialog.VerificationText = "Dont Show Again"; //<--- this is what you want.
//customize the window
dialog.WindowTitle = "Confirm Action";
dialog.Content = "You sure you want to close?";
dialog.MainIcon = TaskDialogIcon.Warning;
//add buttons to the window
dialog.Buttons.Add(butYes);
dialog.Buttons.Add(butNo);
dialog.Buttons.Add(butCancel);
//show window
TaskDialogButton result = dialog.ShowDialog(this);
//get checkbox result
if (dialog.IsVerificationChecked)
{
//do stuff
}
//get window result
if (result != butYes)
{
//if user didn't click "Yes", then cancel the closing.
e.Cancel = true;
return;
}

How to pass data back from Winform to tabpage

if (!existed_channel.Contains(channel_name))
{
if (x)
{
tabpagex.BackColor = Color.Ivory;
tabControl1.TabPages.Add(tabpagex);
client_chat c = new client_chat(channel_name, owner); //Here the client_chat is my Winform that do all the chatting thing.
c.TopLevel = false;
c.Visible = true;
c.BackColor = Color.Ivory;
c.FormBorderStyle = FormBorderStyle.None;
c.Dock = DockStyle.Fill;
tabControl1.TabPages[tab_index].Controls.Add(c); //Here i fill up the tabpage with client_chat winform
tab_index++; //Increment the index everytime i add an tabpage.
existed_channel.Add(channel_name); //Add the name of the page to an arraylist, to make sure everytime there is no duplicate page
}
}
As you can see, when i close one of my Winform(on the tabpage), i have to send back data and modify the tab_index.
I am able to close both Winform and tabpage, but struggling how to send the data back.
I know how to send back data from childForm to parentForm, but the situation here is little different.
You could use a global property on the parent that all controls have access to

Categories

Resources