Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How do i display a messagebox without Titlebar But should have OK & Cancel buttons?
 

How do i display a messagebox without Titlebar But should have OK & Cancel buttons?

C#:
I have to display a messagebox without TitleBar. But must be have "OK" & "Cancel" buttons. When i click "OK" button then Proceed forward steps, or else should not be proceed forward i.e., Cancel the next steps.
---Sri's
My Best Solutions  Thursday, September 10, 2009 4:02 PM
Hello,

Here is the sample code for your requirement.
public partial class MyMsgBox : Form
{
public MyMsgBox(string msg)
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None ;
this.label1.Text = msg;
}

private void btnOk_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK ;
this.Close();
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel ;
this.Close();
}
}
I have created a form with its FormBorderStyle set to FormBorderStyle.None. So when the form load, it doesn't have border. On the form, there is a lable which shows the message. Two buttons, one is Ok, another is Cancel. Before I close the form, I will set the DialogResult.

To use the MyMsgBox, below is the code.
MyMsgBox msgBox = new MyMsgBox("This is my MassageBox");
if (msgBox.ShowDialog() == DialogResult.OK )
{
// Proceed forward steps
}
else
{
// Cancel
}
When user click Ok button, the msgBox's DialogResult is ok, you can Proceed forward steps. If the result is Cancel, then you can cancel the next step.

If I misunderstood something, please feel free to tell me.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework!
Kira Qian  Monday, September 14, 2009 6:39 AM
As far as I know, there is no feature to remove the titlebar from the standard messagebox.

You would need to create your own dialogbox and use it as your messagebox.

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Thursday, September 10, 2009 10:45 PM
thanks..
Can u provide me the code plz..
---Sri's
My Best Solutions  Friday, September 11, 2009 1:55 PM
You can do this with the designer:

1. Add a new form to your project.

2. Add a label (for the text) and two buttons.

3. Double-click on each button and the designer will generate the button click event for you.

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Friday, September 11, 2009 4:06 PM
It almost sounds like you're trying to create a wizard-like form. Take a look at this link: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c290832f-3b84-4200-aa4a-7a5dc4b8b5bb
~~Bonnie Berent [C# MVP]
BonnieB  Saturday, September 12, 2009 4:28 AM
Hello,

Here is the sample code for your requirement.
public partial class MyMsgBox : Form
{
public MyMsgBox(string msg)
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None ;
this.label1.Text = msg;
}

private void btnOk_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK ;
this.Close();
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel ;
this.Close();
}
}
I have created a form with its FormBorderStyle set to FormBorderStyle.None. So when the form load, it doesn't have border. On the form, there is a lable which shows the message. Two buttons, one is Ok, another is Cancel. Before I close the form, I will set the DialogResult.

To use the MyMsgBox, below is the code.
MyMsgBox msgBox = new MyMsgBox("This is my MassageBox");
if (msgBox.ShowDialog() == DialogResult.OK )
{
// Proceed forward steps
}
else
{
// Cancel
}
When user click Ok button, the msgBox's DialogResult is ok, you can Proceed forward steps. If the result is Cancel, then you can cancel the next step.

If I misunderstood something, please feel free to tell me.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework!
Kira Qian  Monday, September 14, 2009 6:39 AM
tanx.. this is what i needs..
---Sri's
My Best Solutions  Monday, September 14, 2009 1:50 PM

You can use google to search for other answers

Custom Search

More Threads

• more events
• Freeze rows at the bottom of the grid
• Making a property bindable?
• Can you nest a DataViewGrid in a DataViewGrid?
• How to bind Label Control to DataView?
• DataView instance problem!
• Link or sharing BindingSources between forms
• Updating a dataset via a binding source
• In Gridview how to give different colors to each cell. How to merge cells in middle, how to show Tool Tip,
• How can I select a specific combobox item within a datagridview