Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. User Control and Window form

User Control and Window form

Scheduled Pinned Locked Moved C#
csharphelpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biswabhusan
    wrote on last edited by
    #1

    Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help

    V X M 3 Replies Last reply
    0
    • B biswabhusan

      Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      delegates and events. It's too difficult to explain in short text, but you can look up examples on google or MSDN.

      V. I found a living worth working for, but haven't found work worth living for.

      1 Reply Last reply
      0
      • B biswabhusan

        Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help

        X Offline
        X Offline
        xstoneheartx
        wrote on last edited by
        #3

        I think the simplest way is: 1- add a usercontrol to your project 2- add a button, named in Button1 to your usercontrol, set Button1 "Modifiers" property to Public. 3- build your project. 4- after adding your user control, named in UserControl1 to your form, add this lines of code: ------------------- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler UserControl1.Button1.Click, AddressOf Button_Click End Sub Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'do your task here End Sub ------------------- 5- what you wanted is done

        L 1 Reply Last reply
        0
        • X xstoneheartx

          I think the simplest way is: 1- add a usercontrol to your project 2- add a button, named in Button1 to your usercontrol, set Button1 "Modifiers" property to Public. 3- build your project. 4- after adding your user control, named in UserControl1 to your form, add this lines of code: ------------------- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler UserControl1.Button1.Click, AddressOf Button_Click End Sub Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'do your task here End Sub ------------------- 5- what you wanted is done

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Unknown C# dialect.

          Luc Pattyn

          X 1 Reply Last reply
          0
          • B biswabhusan

            Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            Hello, Here some code for the suggestions from "V". UserControl code:

            public event EventHandler ButtonClickChanged;

            protected virtual void OnButtonClickChanged(System.EventArgs e)
            {
            if (ButtonClickChanged != null)
            {
            ButtonClickChanged(this, e);
            }
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
            OnButtonClickChanged(System.EventArgs.Empty);
            }

            Forms code:

            public Form1()
            {
            InitializeComponent();

                userControl11.ButtonClickChanged+=new EventHandler(userControl11\_ButtonClickChanged);
            

            }

            private void userControl11_ButtonClickChanged(object sender, EventArgs e)
            {
            //youre code
            }

            Hope that helps! All the best, Martin

            1 Reply Last reply
            0
            • L Luc Pattyn

              Unknown C# dialect.

              Luc Pattyn

              X Offline
              X Offline
              xstoneheartx
              wrote on last edited by
              #6

              add these line of code to your form: private void Button_Click(object sender, System.EventArgs e) { // do your task here } then in your form load event add: UserControl1.Button1.Click += new System.EventHandler(this.Button_Click);

              L 1 Reply Last reply
              0
              • X xstoneheartx

                add these line of code to your form: private void Button_Click(object sender, System.EventArgs e) { // do your task here } then in your form load event add: UserControl1.Button1.Click += new System.EventHandler(this.Button_Click);

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Sure. I think I understood the first time. My remark was it did not really look like C#, the subject of this message board. :)

                Luc Pattyn

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups