Help with LinkLabel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CsharpNoob
    New Member
    • May 2007
    • 9

    Help with LinkLabel

    Community,

    I am very new to using C# and to programming, period.

    I am using visual studio's windows application. I am trying to have the application open up displaying two links. When each link is clicked, I would like for them to open up their own respective windows, whether they be window apps like the forms, or IE windows. I was trying to use the LinkLabels to do this. any help is appreciated.

    Thanks,

    Noob
  • mwalts
    New Member
    • May 2007
    • 38

    #2
    Originally posted by CsharpNoob
    Community,

    I am very new to using C# and to programming, period.

    I am using visual studio's windows application. I am trying to have the application open up displaying two links. When each link is clicked, I would like for them to open up their own respective windows, whether they be window apps like the forms, or IE windows. I was trying to use the LinkLabels to do this. any help is appreciated.

    Thanks,

    Noob
    Ok, your going to want to add this statement near the top (with the other using statments)

    using System.Diagnost ics;

    now in your link Labels on click event you want to add something like this

    Process pIE = new Process();

    pIE.StartInfo.F ileName = "http://TheLink.html";
    pIE.StartInfo.U seShellExecute = true;

    pIE.Start();


    And that should do it

    Heh, I just realized my variable name was pie, delicious pie :p

    Have fun,

    -mwalts

    Comment

    • CsharpNoob
      New Member
      • May 2007
      • 9

      #3
      Thank you very much. The code worked great, but that works for external sites. Now the problem that i'm encoutering is that i've composed two HTML pages that use a combination of both HTML and Javascript. These pages are saved as .html files on my computer, and I moved them into the folder with the .cs file that I made in Visual Studio hoping that it'd find these .html files and open them. How do I get the code provided to open up these files that i've made?



      Originally posted by mwalts
      Ok, your going to want to add this statement near the top (with the other using statments)

      using System.Diagnost ics;

      now in your link Labels on click event you want to add something like this

      Process pIE = new Process();

      pIE.StartInfo.F ileName = "http://TheLink.html";
      pIE.StartInfo.U seShellExecute = true;

      pIE.Start();


      And that should do it

      Heh, I just realized my variable name was pie, delicious pie :p

      Have fun,

      -mwalts

      Comment

      • CsharpNoob
        New Member
        • May 2007
        • 9

        #4
        NEVERMIND!!!

        That is no longer my problem. I remembered that all I have to do is simulate a certain scenario, so that is not an issue anymore. I'm sure i'll have another issue very shortly. :-D

        Comment

        • CsharpNoob
          New Member
          • May 2007
          • 9

          #5
          OK. The problem that I am having now is that when I click on both links, they are refreshing in the SAME window. I need the links to open up their own individual windows. I renamed the second process to pIE2 along with the two .startinfo statements and the one .start statement, but that's not making it open into a new window. any suggestions??



          Originally posted by CsharpNoob
          NEVERMIND!!!

          That is no longer my problem. I remembered that all I have to do is simulate a certain scenario, so that is not an issue anymore. I'm sure i'll have another issue very shortly. :-D

          Comment

          • mwalts
            New Member
            • May 2007
            • 38

            #6
            Originally posted by CsharpNoob
            OK. The problem that I am having now is that when I click on both links, they are refreshing in the SAME window. I need the links to open up their own individual windows. I renamed the second process to pIE2 along with the two .startinfo statements and the one .start statement, but that's not making it open into a new window. any suggestions??
            Hmm, doesn't happen in Internet explorer 7, it will open in a new tab.

            Can I see the exact code your using?

            But it could be that IE recognizes that it is already open and just changes sites instead, in which case, you might have to actually automate IE

            http://www.novicksoftw are.com/TipsAndTricks/tip-csharp-open-ie-browser.htm

            -mwalts

            Comment

            • CsharpNoob
              New Member
              • May 2007
              • 9

              #7
              all of my code is as follows:

              using System;
              using System.Drawing;
              using System.Collecti ons;
              using System.Componen tModel;
              using System.Windows. Forms;
              using System.Data;
              using System.Diagnost ics;


              namespace Problem1Solutio n

              {
              /// <summary>
              /// Summary description for Form1.
              /// </summary>
              public class Form1 : System.Windows. Forms.Form
              {
              private System.Windows. Forms.DataGrid dataGrid1;
              private System.Windows. Forms.LinkLabel linkLabel1;
              private System.Windows. Forms.LinkLabel linkLabel2;
              /// <summary>
              /// Required designer variable.
              /// </summary>
              private System.Componen tModel.Containe r components = null;

              public Form1()
              {
              //
              // Required for Windows Form Designer support
              //
              InitializeCompo nent();

              //
              // TODO: Add any constructor code after InitializeCompo nent call
              //
              }

              /// <summary>
              /// Clean up any resources being used.
              /// </summary>
              protected override void Dispose( bool disposing )
              {
              if( disposing )
              {
              if (components != null)
              {
              components.Disp ose();
              }
              }
              base.Dispose( disposing );
              }

              #region Windows Form Designer generated code
              /// <summary>
              /// Required method for Designer support - do not modify
              /// the contents of this method with the code editor.
              /// </summary>
              private void InitializeCompo nent()
              {
              this.dataGrid1 = new System.Windows. Forms.DataGrid( );
              this.linkLabel1 = new System.Windows. Forms.LinkLabel ();
              this.linkLabel2 = new System.Windows. Forms.LinkLabel ();
              ((System.Compon entModel.ISuppo rtInitialize)(t his.dataGrid1)) .BeginInit();
              this.SuspendLay out();
              //
              // dataGrid1
              //
              this.dataGrid1. DataMember = "";
              this.dataGrid1. HeaderForeColor = System.Drawing. SystemColors.Co ntrolText;
              this.dataGrid1. Location = new System.Drawing. Point(8, 8);
              this.dataGrid1. Name = "dataGrid1" ;
              this.dataGrid1. Size = new System.Drawing. Size(144, 408);
              this.dataGrid1. TabIndex = 0;
              this.dataGrid1. Navigate += new System.Windows. Forms.NavigateE ventHandler(thi s.dataGrid1_Nav igate);
              //
              // linkLabel1
              //
              this.linkLabel1 .ActiveLinkColo r = System.Drawing. Color.RoyalBlue ;
              this.linkLabel1 .Location = new System.Drawing. Point(16, 16);
              this.linkLabel1 .Name = "linkLabel1 ";
              this.linkLabel1 .Size = new System.Drawing. Size(128, 24);
              this.linkLabel1 .TabIndex = 1;
              this.linkLabel1 .TabStop = true;
              this.linkLabel1 .Text = "Document Flow";
              this.linkLabel1 .LinkClicked += new System.Windows. Forms.LinkLabel LinkClickedEven tHandler(this.l inkLabel1_LinkC licked);
              //
              // linkLabel2
              //
              this.linkLabel2 .ActiveLinkColo r = System.Drawing. Color.RoyalBlue ;
              this.linkLabel2 .Location = new System.Drawing. Point(16, 48);
              this.linkLabel2 .Name = "linkLabel2 ";
              this.linkLabel2 .Size = new System.Drawing. Size(128, 24);
              this.linkLabel2 .TabIndex = 2;
              this.linkLabel2 .TabStop = true;
              this.linkLabel2 .Text = "Document Flow";
              this.linkLabel2 .LinkClicked += new System.Windows. Forms.LinkLabel LinkClickedEven tHandler(this.l inkLabel2_LinkC licked);
              //
              // Form1
              //
              this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
              this.ClientSize = new System.Drawing. Size(536, 437);
              this.Controls.A dd(this.linkLab el2);
              this.Controls.A dd(this.linkLab el1);
              this.Controls.A dd(this.dataGri d1);
              this.Name = "Form1";
              this.Text = "Form1";
              ((System.Compon entModel.ISuppo rtInitialize)(t his.dataGrid1)) .EndInit();
              this.ResumeLayo ut(false);

              }
              #endregion

              /// <summary>
              /// The main entry point for the application.
              /// </summary>
              [STAThread]
              static void Main()
              {
              Application.Run (new Form1());
              }

              private void dataGrid1_Navig ate(object sender, System.Windows. Forms.NavigateE ventArgs ne)
              {



              }
              private void linkLabel1_Link Clicked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)
              {
              Process pIE = new Process();

              pIE.StartInfo.F ileName = "http://www.google.com" ;
              pIE.StartInfo.U seShellExecute = true;

              pIE.Start();

              }

              private void linkLabel2_Link Clicked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)
              {
              Process pIE2 = new Process();

              pIE2.StartInfo. FileName = "http://www.yahoo.com";
              pIE2.StartInfo. UseShellExecute = true;

              pIE2.Start();

              }
              }
              }









              Originally posted by mwalts
              Hmm, doesn't happen in Internet explorer 7, it will open in a new tab.

              Can I see the exact code your using?

              But it could be that IE recognizes that it is already open and just changes sites instead, in which case, you might have to actually automate IE

              http://www.novicksoftw are.com/TipsAndTricks/tip-csharp-open-ie-browser.htm

              -mwalts

              Comment

              • mwalts
                New Member
                • May 2007
                • 38

                #8
                Originally posted by CsharpNoob
                all of my code is as follows:

                using System;
                using System.Drawing;
                using System.Collecti ons;
                using System.Componen tModel;
                using System.Windows. Forms;
                using System.Data;
                using System.Diagnost ics;


                namespace Problem1Solutio n

                {
                /// <summary>
                /// Summary description for Form1.
                /// </summary>
                public class Form1 : System.Windows. Forms.Form
                {
                private System.Windows. Forms.DataGrid dataGrid1;
                private System.Windows. Forms.LinkLabel linkLabel1;
                private System.Windows. Forms.LinkLabel linkLabel2;
                /// <summary>
                /// Required designer variable.
                /// </summary>
                private System.Componen tModel.Containe r components = null;

                public Form1()
                {
                //
                // Required for Windows Form Designer support
                //
                InitializeCompo nent();

                //
                // TODO: Add any constructor code after InitializeCompo nent call
                //
                }

                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                protected override void Dispose( bool disposing )
                {
                if( disposing )
                {
                if (components != null)
                {
                components.Disp ose();
                }
                }
                base.Dispose( disposing );
                }

                #region Windows Form Designer generated code
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeCompo nent()
                {
                this.dataGrid1 = new System.Windows. Forms.DataGrid( );
                this.linkLabel1 = new System.Windows. Forms.LinkLabel ();
                this.linkLabel2 = new System.Windows. Forms.LinkLabel ();
                ((System.Compon entModel.ISuppo rtInitialize)(t his.dataGrid1)) .BeginInit();
                this.SuspendLay out();
                //
                // dataGrid1
                //
                this.dataGrid1. DataMember = "";
                this.dataGrid1. HeaderForeColor = System.Drawing. SystemColors.Co ntrolText;
                this.dataGrid1. Location = new System.Drawing. Point(8, 8);
                this.dataGrid1. Name = "dataGrid1" ;
                this.dataGrid1. Size = new System.Drawing. Size(144, 408);
                this.dataGrid1. TabIndex = 0;
                this.dataGrid1. Navigate += new System.Windows. Forms.NavigateE ventHandler(thi s.dataGrid1_Nav igate);
                //
                // linkLabel1
                //
                this.linkLabel1 .ActiveLinkColo r = System.Drawing. Color.RoyalBlue ;
                this.linkLabel1 .Location = new System.Drawing. Point(16, 16);
                this.linkLabel1 .Name = "linkLabel1 ";
                this.linkLabel1 .Size = new System.Drawing. Size(128, 24);
                this.linkLabel1 .TabIndex = 1;
                this.linkLabel1 .TabStop = true;
                this.linkLabel1 .Text = "Document Flow";
                this.linkLabel1 .LinkClicked += new System.Windows. Forms.LinkLabel LinkClickedEven tHandler(this.l inkLabel1_LinkC licked);
                //
                // linkLabel2
                //
                this.linkLabel2 .ActiveLinkColo r = System.Drawing. Color.RoyalBlue ;
                this.linkLabel2 .Location = new System.Drawing. Point(16, 48);
                this.linkLabel2 .Name = "linkLabel2 ";
                this.linkLabel2 .Size = new System.Drawing. Size(128, 24);
                this.linkLabel2 .TabIndex = 2;
                this.linkLabel2 .TabStop = true;
                this.linkLabel2 .Text = "Document Flow";
                this.linkLabel2 .LinkClicked += new System.Windows. Forms.LinkLabel LinkClickedEven tHandler(this.l inkLabel2_LinkC licked);
                //
                // Form1
                //
                this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
                this.ClientSize = new System.Drawing. Size(536, 437);
                this.Controls.A dd(this.linkLab el2);
                this.Controls.A dd(this.linkLab el1);
                this.Controls.A dd(this.dataGri d1);
                this.Name = "Form1";
                this.Text = "Form1";
                ((System.Compon entModel.ISuppo rtInitialize)(t his.dataGrid1)) .EndInit();
                this.ResumeLayo ut(false);

                }
                #endregion

                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                [STAThread]
                static void Main()
                {
                Application.Run (new Form1());
                }

                private void dataGrid1_Navig ate(object sender, System.Windows. Forms.NavigateE ventArgs ne)
                {



                }
                private void linkLabel1_Link Clicked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)
                {
                Process pIE = new Process();

                pIE.StartInfo.F ileName = "http://www.google.com" ;
                pIE.StartInfo.U seShellExecute = true;

                pIE.Start();

                }

                private void linkLabel2_Link Clicked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)
                {
                Process pIE2 = new Process();

                pIE2.StartInfo. FileName = "http://www.yahoo.com";
                pIE2.StartInfo. UseShellExecute = true;

                pIE2.Start();

                }
                }
                }
                yeah, that should have done it.

                I don't have the old version of IE anymore so I can't reproduce it.

                Looks like you're stuck with automation.

                Or, if you know for sure where IE is, you can do something like this

                pIE.FileName = @"""C:\Progr am Files\Internet Explorer\iexplo re.exe""";
                pIE.Arguments = "-new www.google.com" ;
                pIE.Start();

                but if you are running it on more then one computer, and IE is in a different place (unlikely I'll grant) then it will break.

                -mwalts

                Comment

                • CsharpNoob
                  New Member
                  • May 2007
                  • 9

                  #9
                  wow. I thank you for your help and dedication to aiding me with resolving this problem. Your help has been GREATLY appreciated. I will either attempt to do it with the method that you provided, or just deal with it.

                  Thank You VERY much,

                  CsharpNOOB


                  Originally posted by mwalts
                  yeah, that should have done it.

                  I don't have the old version of IE anymore so I can't reproduce it.

                  Looks like you're stuck with automation.

                  Or, if you know for sure where IE is, you can do something like this

                  pIE.FileName = @"""C:\Progr am Files\Internet Explorer\iexplo re.exe""";
                  pIE.Arguments = "-new www.google.com" ;
                  pIE.Start();

                  but if you are running it on more then one computer, and IE is in a different place (unlikely I'll grant) then it will break.

                  -mwalts

                  Comment

                  Working...