PC Review


Reply
Thread Tools Rate Thread

Creating own custom dialogs

 
 
=?ISO-8859-1?Q?Mikko_Nyl=E9n?=
Guest
Posts: n/a
 
      20th Mar 2005
After playing a while with System.Windows.Forms, I decided to try
creating my own custom dialogs from scratch. After a bit of googling, I
found out that there's not so much examples of doing own custom dialogs.

So, I'm asking what is the preferred way for creating your own custom
dialogs from scratch? I think it would look a little absurd to inherit
Form for a dialog and the only alternative I was able to find was
inheriting CommonDialog.

The ColorDialog, FontDialog and others inherit from CommonDialog, so I
feel like it would be the preferred way. But the problem is that I can't
find any examples and the documentation of that class in MSDN isn't so
good. For example, when I override RunDialog() and Reset(), what they
should actually do? Is there any examples available?

Thanks in advance.

- Mikko Nylén
 
Reply With Quote
 
 
 
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      21st Mar 2005
Creating objects based upon Form is the correct way to make custom dialogs.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Mikko Nylén" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> After playing a while with System.Windows.Forms, I decided to try creating
> my own custom dialogs from scratch. After a bit of googling, I found out
> that there's not so much examples of doing own custom dialogs.
>
> So, I'm asking what is the preferred way for creating your own custom
> dialogs from scratch? I think it would look a little absurd to inherit
> Form for a dialog and the only alternative I was able to find was
> inheriting CommonDialog.
>
> The ColorDialog, FontDialog and others inherit from CommonDialog, so I
> feel like it would be the preferred way. But the problem is that I can't
> find any examples and the documentation of that class in MSDN isn't so
> good. For example, when I override RunDialog() and Reset(), what they
> should actually do? Is there any examples available?
>
> Thanks in advance.
>
> - Mikko Nylén



 
Reply With Quote
 
=?ISO-8859-1?Q?Mikko_Nyl=E9n?=
Guest
Posts: n/a
 
      21st Mar 2005
Bob Powell [MVP] wrote:
> Creating objects based upon Form is the correct way to make custom dialogs.
>


Okay. Thanks for the reply.

But what for the CommonDialog is then used to? Is it used just for the
existing dialogs in .NET Framework (ColorDialog, FontDialog etc.) or
should it be used in special cases or something?

- Mikko Nylén
 
Reply With Quote
 
Jason Black [MSFT]
Guest
Posts: n/a
 
      21st Mar 2005
To be a little more specific:

In the Solution Explorer window, right-click on the project you want to add
the dialog to, and select Add->Windows Form from the context menu. You'll
be asked for a name for the new Form's class, and you'll get a blank form
just like when you create a WinForms app, and a new .cs file added to your
project. Add input controls and so forth just like you would for your main
application UI. Add an "OK" button, and make sure that the button's
DialogResult property is set to "OK". Similarly, add a "Cancel" button with
a DialogResult of (surprise surprise) "Cancel".

Now view the code for the dialog's .cs file. In the code editor, add some
public properties for accessing the values in the dialog box's input
controls. You need a "get" accessor on the properties in order to read the
values, but you can also have "set" accessors so that the caller can set
default values for the input controls if necessary. Set accessors are
usually optional, houwver, as in most cases you probably know what a good
default value is ahead of time, and can set that directly through the Forms
Designer.

For example, if your dialog was asking the user for width and height values
for creating a bitmap, you might add something like this:

class myDialog: System.Windows.Forms.Form {
public int Width {
get { return (int)WidthEntry.Value; }
set { WidthEntry.Value = value; }
}
public int Height {
get { return (int)HeightEntry.Value; }
set { HeightEntry.Value = value; }
}
// everything else is what the Forms Designer generated for you
}

In your application, you use it by creating a new "myDialog" object, and
call the ShowDialog() method to display it to the user. After that, treat
it just like you would treat any of the built-in dialogs such as
ColorDialog: check the return value from ShowDialog, get the relevant values
out of the dialog's public fields/properties, and then do whatever you need
to do with them. In this example, maybe something like this:

myDialog d = new myDialog();
if(d.ShowDialog() == DialogResult.OK) {
Bitmap b = new Bitmap(d.Width, d.Height);
}


"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:(E-Mail Removed)...
> Creating objects based upon Form is the correct way to make custom
> dialogs.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Mikko Nylén" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> After playing a while with System.Windows.Forms, I decided to try
>> creating my own custom dialogs from scratch. After a bit of googling, I
>> found out that there's not so much examples of doing own custom dialogs.
>>
>> So, I'm asking what is the preferred way for creating your own custom
>> dialogs from scratch? I think it would look a little absurd to inherit
>> Form for a dialog and the only alternative I was able to find was
>> inheriting CommonDialog.
>>
>> The ColorDialog, FontDialog and others inherit from CommonDialog, so I
>> feel like it would be the preferred way. But the problem is that I can't
>> find any examples and the documentation of that class in MSDN isn't so
>> good. For example, when I override RunDialog() and Reset(), what they
>> should actually do? Is there any examples available?
>>
>> Thanks in advance.
>>
>> - Mikko Nylén

>
>



 
Reply With Quote
 
Sergey Novogilov
Guest
Posts: n/a
 
      23rd Mar 2005
Hi, just FYI:

Dialog Workshop .NET(www.componentage.com) allows to
extend almost all standard dialogs in many ways (add custom controls,
customize dialog size, position and icon, etc.) without writing a line of
code and
without using resources, etc. and without leaving Visual Studio.


Sergey

"Mikko Nylén" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> After playing a while with System.Windows.Forms, I decided to try creating
> my own custom dialogs from scratch. After a bit of googling, I found out
> that there's not so much examples of doing own custom dialogs.
>
> So, I'm asking what is the preferred way for creating your own custom
> dialogs from scratch? I think it would look a little absurd to inherit
> Form for a dialog and the only alternative I was able to find was
> inheriting CommonDialog.
>
> The ColorDialog, FontDialog and others inherit from CommonDialog, so I
> feel like it would be the preferred way. But the problem is that I can't
> find any examples and the documentation of that class in MSDN isn't so
> good. For example, when I override RunDialog() and Reset(), what they
> should actually do? Is there any examples available?
>
> Thanks in advance.
>
> - Mikko Nylén



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Parameter Dialogs for Reports Kaylen Microsoft Access Reports 2 23rd Jan 2009 07:50 PM
Custom deployment wizard dialogs ahmed Microsoft Dot NET 1 12th Jun 2007 12:25 PM
Creating generic dialogs =?Utf-8?B?UG9udGlNYXg=?= Microsoft ASP .NET 1 9th Feb 2005 08:50 PM
Creating Dialogs Thore Berntsen Microsoft Dot NET Compact Framework 2 12th Mar 2004 09:08 AM
PrintDlg and custom Dialogs Shaun Wilde Microsoft Dot NET Compact Framework 0 24th Jul 2003 07:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:23 AM.