Click here to Skip to main content
15,911,327 members
Home / Discussions / C#
   

C#

 
Questioncontrol Windows Media player Pin
Member 997255825-Feb-14 4:57
Member 997255825-Feb-14 4:57 
Questionhow to confirm Security risk alert in C# web browser Pin
Abhinaw Kumar Singh25-Feb-14 2:16
professionalAbhinaw Kumar Singh25-Feb-14 2:16 
AnswerRe: how to confirm Security risk alert in C# web browser Pin
Pete O'Hanlon25-Feb-14 3:11
mvePete O'Hanlon25-Feb-14 3:11 
GeneralRe: how to confirm Security risk alert in C# web browser Pin
Abhinaw Kumar Singh25-Feb-14 6:18
professionalAbhinaw Kumar Singh25-Feb-14 6:18 
GeneralRe: how to confirm Security risk alert in C# web browser Pin
Richard Deeming25-Feb-14 7:16
mveRichard Deeming25-Feb-14 7:16 
GeneralRe: how to confirm Security risk alert in C# web browser Pin
Bernhard Hiller25-Feb-14 21:39
Bernhard Hiller25-Feb-14 21:39 
QuestionCreating DTO using TDD approach Pin
ramsai197325-Feb-14 1:22
ramsai197325-Feb-14 1:22 
Questionhow to restore a sql database programmatically in c#? Pin
rincy sivan24-Feb-14 23:35
rincy sivan24-Feb-14 23:35 
AnswerRe: how to restore a sql database programmatically in c#? Pin
Nicholas Marty24-Feb-14 23:54
professionalNicholas Marty24-Feb-14 23:54 
AnswerRe: how to restore a sql database programmatically in c#? Pin
OriginalGriff24-Feb-14 23:57
mveOriginalGriff24-Feb-14 23:57 
AnswerRe: how to restore a sql database programmatically in c#? Pin
Raj Mouli26-Feb-14 19:44
Raj Mouli26-Feb-14 19:44 
AnswerRe: how to restore a sql database programmatically in c#? Pin
Raj Mouli26-Feb-14 19:45
Raj Mouli26-Feb-14 19:45 
QuestionSerialComm Port to send and receive sms Pin
yomag4chi24-Feb-14 21:51
yomag4chi24-Feb-14 21:51 
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 

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.