Click here to Skip to main content
15,513,655 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I'll to close all the windows? Pin
Stefan Troschuetz15-Feb-07 4:29
Stefan Troschuetz15-Feb-07 4:29 
GeneralRe: How do I'll to close all the windows? Pin
alex.almeida15-Feb-07 7:21
alex.almeida15-Feb-07 7:21 
QuestionHow to stop a particular thread from a ThreadPool Pin
nasambur15-Feb-07 1:17
nasambur15-Feb-07 1:17 
AnswerRe: How to stop a particular thread from a ThreadPool Pin
Martin#15-Feb-07 1:50
Martin#15-Feb-07 1:50 
QuestionEvent fire in design-time Pin
gattish15-Feb-07 0:46
gattish15-Feb-07 0:46 
AnswerRe: Event fire in design-time Pin
Jakub Mller15-Feb-07 1:21
Jakub Mller15-Feb-07 1:21 
GeneralRe: Event fire in design-time Pin
gattish15-Feb-07 1:34
gattish15-Feb-07 1:34 
GeneralRe: Event fire in design-time Pin
Jakub Mller15-Feb-07 1:58
Jakub Mller15-Feb-07 1: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 2:23
professionalThomas Stockwell15-Feb-07 2:23 
GeneralRe: Event fire in design-time Pin
gattish15-Feb-07 3:02
gattish15-Feb-07 3:02 
GeneralRe: Event fire in design-time Pin
Thomas Stockwell15-Feb-07 10:22
professionalThomas Stockwell15-Feb-07 10:22 
QuestionEnumerate types from referenced assembly in VS2005 macro Pin
Jakub Mller15-Feb-07 0:45
Jakub Mller15-Feb-07 0:45 
QuestionMap some parts of an image [modified] Pin
Muammar©15-Feb-07 0:26
Muammar©15-Feb-07 0:26 
AnswerRe: Map some parts of an image Pin
benjymous15-Feb-07 0:49
benjymous15-Feb-07 0:49 
GeneralRe: Map some parts of an image Pin
Muammar©15-Feb-07 0:57
Muammar©15-Feb-07 0:57 
GeneralRe: Map some parts of an image Pin
Christian Graus15-Feb-07 1:00
mveChristian Graus15-Feb-07 1:00 
GeneralRe: Map some parts of an image Pin
Muammar©15-Feb-07 1:10
Muammar©15-Feb-07 1:10 
Questiontext Length in pixel?? Pin
MHASSANF15-Feb-07 0:08
MHASSANF15-Feb-07 0:08 
AnswerRe: text Length in pixel?? Pin
Martin#15-Feb-07 0:35
Martin#15-Feb-07 0:35 
AnswerRe: text Length in pixel?? Pin
Martin#15-Feb-07 0:44
Martin#15-Feb-07 0:44 
QuestionMapping Images?? Pin
Muammar©14-Feb-07 23:58
Muammar©14-Feb-07 23:58 
QuestionGetting Bandwidth Speed Pin
Icarus12314-Feb-07 23:24
Icarus12314-Feb-07 23:24 
AnswerRe: Getting Bandwidth Speed Pin
BRShroyer15-Feb-07 7:25
BRShroyer15-Feb-07 7:25 
QuestionObtain de age of a computer Pin
AlbertONL14-Feb-07 23:18
AlbertONL14-Feb-07 23:18 
QuestionGoTo Line Implementation Pin
hiremath7114-Feb-07 23:06
hiremath7114-Feb-07 23: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.