Click here to Skip to main content
15,892,737 members
Home / Discussions / C#
   

C#

 
AnswerRe: SerialComm Port to send and receive sms Pin
Richard MacCutchan24-Feb-14 22:04
mveRichard MacCutchan24-Feb-14 22:04 
AnswerRe: SerialComm Port to send and receive sms Pin
OriginalGriff24-Feb-14 22:29
mveOriginalGriff24-Feb-14 22:29 
Questionhow to prevent form open twice Pin
Aman Susanto24-Feb-14 2:50
Aman Susanto24-Feb-14 2:50 
AnswerRe: how to prevent form open twice Pin
johannesnestler24-Feb-14 3:15
johannesnestler24-Feb-14 3:15 
GeneralRe: how to prevent form open twice Pin
Eddy Vluggen24-Feb-14 6:57
professionalEddy Vluggen24-Feb-14 6:57 
GeneralRe: how to prevent form open twice Pin
johannesnestler24-Feb-14 8:12
johannesnestler24-Feb-14 8:12 
AnswerRe: how to prevent form open twice Pin
BillWoodruff24-Feb-14 6:41
professionalBillWoodruff24-Feb-14 6:41 
AnswerRe: how to prevent form open twice Pin
Richard Deeming24-Feb-14 9:00
mveRichard Deeming24-Feb-14 9:00 
Looking at your code, the problem appears to be with the frm.Focus(); line:
  1. You create a new instance of the form type;
  2. You check to see if there is an open form of the same type;
  3. If there is, you call the Focus method on the new form instance;

I suspect that calling Focus on an invisible form causes it to be shown.

Try something like this instead:
C#
private Form FindOpenFormOfType(Type formType)
{
    foreach (Form form in Application.OpenForms)
    {
        if (form.GetType() == formType)
        {
            return form;
        }
    }
    
    return null;
}

private void klikMenu(object sender, EventArgs e)
{
    string sFormName = "AIO_System." + ((ToolStripMenuItem)sender).Tag.ToString();
    System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
    Type formType = asm.GetType(sFormName);
    
    Form frm = FindOpenFormOfType(formType);
    if (frm == null)
    {
        frm = (Form)Activator.CreateInstance(formType);
        frm.Owner = this;
        frm.Show();
    }
    else
    {
        frm.Focus();
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: how to prevent form open twice Pin
BillWoodruff24-Feb-14 13:21
professionalBillWoodruff24-Feb-14 13:21 
SuggestionRe: how to prevent form open twice Pin
azhar9925-Feb-14 20:50
azhar9925-Feb-14 20:50 
QuestionA first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in Microsoft.Phone.Data.Internal.ni.dll Pin
Gene Lim23-Feb-14 22:40
Gene Lim23-Feb-14 22:40 
AnswerRe: A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in Microsoft.Phone.Data.Internal.ni.dll Pin
Naveen Kumar Krishnan24-Feb-14 1:18
Naveen Kumar Krishnan24-Feb-14 1:18 
GeneralRe: A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in Microsoft.Phone.Data.Internal.ni.dll Pin
Gene Lim24-Feb-14 2:53
Gene Lim24-Feb-14 2:53 
QuestionSQL SELECT Current User c# Pin
mcgurdan22-Feb-14 9:49
mcgurdan22-Feb-14 9:49 
AnswerRe: SQL SELECT Current User c# Pin
Ravi Bhavnani22-Feb-14 11:13
professionalRavi Bhavnani22-Feb-14 11:13 
QuestionHow do I inherit ComboBox to implement my function Pin
Member 1041329221-Feb-14 21:50
professionalMember 1041329221-Feb-14 21:50 
AnswerRe: How do I inherit ComboBox to implement my function Pin
Richard MacCutchan21-Feb-14 23:10
mveRichard MacCutchan21-Feb-14 23:10 
GeneralRe: How do I inherit ComboBox to implement my function Pin
BillWoodruff22-Feb-14 5:44
professionalBillWoodruff22-Feb-14 5:44 
GeneralRe: How do I inherit ComboBox to implement my function Pin
Dave Kreskowiak22-Feb-14 8:11
mveDave Kreskowiak22-Feb-14 8:11 
GeneralRe: How do I inherit ComboBox to implement my function Pin
BillWoodruff22-Feb-14 8:30
professionalBillWoodruff22-Feb-14 8:30 
GeneralRe: How do I inherit ComboBox to implement my function Pin
Ravi Bhavnani22-Feb-14 11:15
professionalRavi Bhavnani22-Feb-14 11:15 
GeneralRe: How do I inherit ComboBox to implement my function Pin
Dave Kreskowiak23-Feb-14 4:47
mveDave Kreskowiak23-Feb-14 4:47 
GeneralRe: How do I inherit ComboBox to implement my function Pin
Ravi Bhavnani23-Feb-14 6:34
professionalRavi Bhavnani23-Feb-14 6:34 
GeneralRe: How do I inherit ComboBox to implement my function Pin
Richard MacCutchan23-Feb-14 21:59
mveRichard MacCutchan23-Feb-14 21:59 
GeneralRe: How do I inherit ComboBox to implement my function Pin
Member 1041329223-Feb-14 13:53
professionalMember 1041329223-Feb-14 13:53 

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.