Click here to Skip to main content
15,881,852 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I'll to close all the windows? Pin
Stefan Troschuetz15-Feb-07 3:29
Stefan Troschuetz15-Feb-07 3:29 
GeneralRe: How do I'll to close all the windows? Pin
alex.almeida15-Feb-07 6:21
alex.almeida15-Feb-07 6:21 
QuestionHow to stop a particular thread from a ThreadPool Pin
nasambur15-Feb-07 0:17
nasambur15-Feb-07 0:17 
AnswerRe: How to stop a particular thread from a ThreadPool Pin
Martin#15-Feb-07 0:50
Martin#15-Feb-07 0:50 
QuestionEvent fire in design-time Pin
gattish14-Feb-07 23:46
gattish14-Feb-07 23:46 
AnswerRe: Event fire in design-time Pin
Jakub Mller15-Feb-07 0:21
Jakub Mller15-Feb-07 0:21 
GeneralRe: Event fire in design-time Pin
gattish15-Feb-07 0:34
gattish15-Feb-07 0:34 
GeneralRe: Event fire in design-time Pin
Jakub Mller15-Feb-07 0:58
Jakub Mller15-Feb-07 0:58 
Class "System.ComponentModel.Component" has "Site" property typed as "ISite". The ISite interface has "DesignMode" property typed as "bool".

If value of "Site" property is not null, the component propably is in some designer. But if "Site.DesignMode == true", you can be sure.

So following method return true, if specified component is in designer:
bool IsInDesignMode(Component component) {
    ISite site = component.Site;
    bool ret = ( site != null && site.DesignMode );
    return ret;
}


Class "System.Windows.Forms.Control" has "Site" property too and besides protected property "DesignMode" ( which's body is similar to 'IsInDesignMode' method ).

So, if you want to find out, if clicked button is in design mode, you check value of their "Site" property.

Example:
public class MyButton : Button {
    protected override void OnClick( EventArgs e ){
        if ( this.DesignMode ) { // use protected property
            MessageBox.Show( "This button is in design mode. Raising event 'Click' is verboten." );
        }
        else {
            base.OnClick( e );
        }
    }
}


Or:

public class MyForm : Form {
    private Button button1;
    ...
    ...
    ...
    private void button1_Click(object sender, EventArgs e){
        ISite site = this.button1.Site;
        if ( site != null && site.DesignMode ){
            MessageBox.Show("Button was clicked in design mode.");
        }
        else{
            MessageBox.Show("Button was clicked in run-time mode.");
        }
    }
}


If you compose usercontrols in hierarchy, only the most top control in designer has value of "DesignMode" property set to "true".
You must search in hierarchy for real state of design mode.

Example:
<code>public class MyControl_A : UserControl{
    private MyControl_B myCtl_B;

    public MyControl_A(){
        this.myCtl_B = new MyControl_B();
        this.Controls.Add(this.myCtl_B);
    }
}

public class MyControl_B : UserControl{
    protected bool IsInDesignMode(){
        bool ret = false;

        Control ctl = this;
        while( ctl != null && ret == false ){
            ISite site = ctl.Site;
            if ( site != null ){
                ret = site.DesignMode;
            }
            
            ctl = ctl.Parent;
        }

        return ret;
    }
    protected override void OnClick(EventArgs e){
        if ( this.IsInDesignMode() ){
            MessageBox.Show("This control is in design mode.");
        }
        else{
            base.OnClick(e);
        }
    }
}


Geniality is in simplicity.

AnswerRe: Event fire in design-time Pin
Thomas Stockwell15-Feb-07 1:23
professionalThomas Stockwell15-Feb-07 1:23 
GeneralRe: Event fire in design-time Pin
gattish15-Feb-07 2:02
gattish15-Feb-07 2:02 
GeneralRe: Event fire in design-time Pin
Thomas Stockwell15-Feb-07 9:22
professionalThomas Stockwell15-Feb-07 9:22 
QuestionEnumerate types from referenced assembly in VS2005 macro Pin
Jakub Mller14-Feb-07 23:45
Jakub Mller14-Feb-07 23:45 
QuestionMap some parts of an image [modified] Pin
Muammar©14-Feb-07 23:26
Muammar©14-Feb-07 23:26 
AnswerRe: Map some parts of an image Pin
benjymous14-Feb-07 23:49
benjymous14-Feb-07 23:49 
GeneralRe: Map some parts of an image Pin
Muammar©14-Feb-07 23:57
Muammar©14-Feb-07 23:57 
GeneralRe: Map some parts of an image Pin
Christian Graus15-Feb-07 0:00
protectorChristian Graus15-Feb-07 0:00 
GeneralRe: Map some parts of an image Pin
Muammar©15-Feb-07 0:10
Muammar©15-Feb-07 0:10 
Questiontext Length in pixel?? Pin
MHASSANF14-Feb-07 23:08
MHASSANF14-Feb-07 23:08 
AnswerRe: text Length in pixel?? Pin
Martin#14-Feb-07 23:35
Martin#14-Feb-07 23:35 
AnswerRe: text Length in pixel?? Pin
Martin#14-Feb-07 23:44
Martin#14-Feb-07 23:44 
QuestionMapping Images?? Pin
Muammar©14-Feb-07 22:58
Muammar©14-Feb-07 22:58 
QuestionGetting Bandwidth Speed Pin
Icarus12314-Feb-07 22:24
Icarus12314-Feb-07 22:24 
AnswerRe: Getting Bandwidth Speed Pin
BRShroyer15-Feb-07 6:25
BRShroyer15-Feb-07 6:25 
QuestionObtain de age of a computer Pin
AlbertONL14-Feb-07 22:18
AlbertONL14-Feb-07 22:18 
QuestionGoTo Line Implementation Pin
hiremath7114-Feb-07 22:06
hiremath7114-Feb-07 22:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.