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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Custom Window Control

Custom Window Control

Scheduled Pinned Locked Moved C#
htmldesignhelpquestion
10 Posts 4 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.
  • N Offline
    N Offline
    Nisha Agrawal
    wrote on last edited by
    #1

    Hi All, I want to design a custom window control which can be derived from textbox and to which i can add another control like month calendar or keyboard panel. I have tried user control for this but then i can't derive this from textbox and if i design a custom control that derives from textbox class then how i can add keyboard panel/ month calendar to it? If i have to design a web control instead of window control then i can add controls to inherited textbox control via rendering the required html. but how this task can be done in window control? [Addition]The idea in my mind is design it like user control and then expose the required properties/ event through the custom control. Is it a right solution? or is there a better solution for this problem?[/Addition]

    D T L N 4 Replies Last reply
    0
    • N Nisha Agrawal

      Hi All, I want to design a custom window control which can be derived from textbox and to which i can add another control like month calendar or keyboard panel. I have tried user control for this but then i can't derive this from textbox and if i design a custom control that derives from textbox class then how i can add keyboard panel/ month calendar to it? If i have to design a web control instead of window control then i can add controls to inherited textbox control via rendering the required html. but how this task can be done in window control? [Addition]The idea in my mind is design it like user control and then expose the required properties/ event through the custom control. Is it a right solution? or is there a better solution for this problem?[/Addition]

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Why are placing all that inside a TextBox? Maybe if you can tell the purpose of having such control, one can respons in a better way. You can create a user control that will have a TextBox, and a Keyboard panel and a month calendar.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      1 Reply Last reply
      0
      • N Nisha Agrawal

        Hi All, I want to design a custom window control which can be derived from textbox and to which i can add another control like month calendar or keyboard panel. I have tried user control for this but then i can't derive this from textbox and if i design a custom control that derives from textbox class then how i can add keyboard panel/ month calendar to it? If i have to design a web control instead of window control then i can add controls to inherited textbox control via rendering the required html. but how this task can be done in window control? [Addition]The idea in my mind is design it like user control and then expose the required properties/ event through the custom control. Is it a right solution? or is there a better solution for this problem?[/Addition]

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        It is posible to add extra control to a textbox by inheritance, but it is not simple. A drop down control can be added by dynamically displaying the dropdown control positioned relative to the textbox in it's parent at runtime in appripriate event eg. the right mouse click. However most often you would want a User control to do this. It is much easier. Out of interest, why would you want a keyboard drop down on a windows app? Or are you developing for Windows mobile? Sorry, even then it does not make sense to me. And a calendar drop down only makes sense on a date picker which already has one. What is it that you really want to add to the textbox?

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

        1 Reply Last reply
        0
        • N Nisha Agrawal

          Hi All, I want to design a custom window control which can be derived from textbox and to which i can add another control like month calendar or keyboard panel. I have tried user control for this but then i can't derive this from textbox and if i design a custom control that derives from textbox class then how i can add keyboard panel/ month calendar to it? If i have to design a web control instead of window control then i can add controls to inherited textbox control via rendering the required html. but how this task can be done in window control? [Addition]The idea in my mind is design it like user control and then expose the required properties/ event through the custom control. Is it a right solution? or is there a better solution for this problem?[/Addition]

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Create a UserControl and add the constituent controls in it, for example, text box, month calendar, etc. Expose the properties, events and methods of the constituent controls by creating properties, events and methods for the UserControl and mapping them to the constituent controls. For example:

          class MyTextBox {
          TextBox textBox1 = new TextBox();
          EventHandler TextChanged;

          public MyTextBox() {
              textBox1.TextChanged += EventHandler(textBox1\_TextChanged);
          }
          
          //Expose property
          public string Text {
              get { return textBox1.Text; }
              set { textBox1.Text = value; }
          }
          
          //Expose event
          private void textBox1\_TextChanged(object sender, EventArgs e) {
              if (TextChanged != null)
                  TextChanged();
          }
          
          //Expose method
          public void Clear() {
              textBox1.Clear();
          }
          

          }

          Custom controls can only be used to extend the functionality of an existing control. You cannot add additional controls to it.

          1 Reply Last reply
          0
          • N Nisha Agrawal

            Hi All, I want to design a custom window control which can be derived from textbox and to which i can add another control like month calendar or keyboard panel. I have tried user control for this but then i can't derive this from textbox and if i design a custom control that derives from textbox class then how i can add keyboard panel/ month calendar to it? If i have to design a web control instead of window control then i can add controls to inherited textbox control via rendering the required html. but how this task can be done in window control? [Addition]The idea in my mind is design it like user control and then expose the required properties/ event through the custom control. Is it a right solution? or is there a better solution for this problem?[/Addition]

            N Offline
            N Offline
            Nisha Agrawal
            wrote on last edited by
            #5

            Thanks to all for taking intrest in my problem. Now i just understood that i am making some mistake. When i searched CP more, i got this article A Touch Screen Keyboard Control in WPF[^]. It was my exact requirement but i have to design a window control not WPF. Now i got the idea from this article that i should display the keyboard panel as another window not to include panel in the control itself.

            D T 2 Replies Last reply
            0
            • N Nisha Agrawal

              Thanks to all for taking intrest in my problem. Now i just understood that i am making some mistake. When i searched CP more, i got this article A Touch Screen Keyboard Control in WPF[^]. It was my exact requirement but i have to design a window control not WPF. Now i got the idea from this article that i should display the keyboard panel as another window not to include panel in the control itself.

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              If you really need a new window for the keyboard, fine. Or else you can create a user control with SplitPanel where one panel will have the textbox and other would have the keyboard.

              50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

              N 1 Reply Last reply
              0
              • N Nisha Agrawal

                Thanks to all for taking intrest in my problem. Now i just understood that i am making some mistake. When i searched CP more, i got this article A Touch Screen Keyboard Control in WPF[^]. It was my exact requirement but i have to design a window control not WPF. Now i got the idea from this article that i should display the keyboard panel as another window not to include panel in the control itself.

                T Offline
                T Offline
                The Man from U N C L E
                wrote on last edited by
                #7

                Touch screen. now it all makes more sense.

                If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

                1 Reply Last reply
                0
                • D dan sh

                  If you really need a new window for the keyboard, fine. Or else you can create a user control with SplitPanel where one panel will have the textbox and other would have the keyboard.

                  50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

                  N Offline
                  N Offline
                  Nisha Agrawal
                  wrote on last edited by
                  #8

                  but then my problem remains same that i won't be able to inherit this control with TextBox so that all it's properties and events are avialable to the Control User. So now if there is any idea for this problem then i'll be really thankful to you.

                  L 1 Reply Last reply
                  0
                  • N Nisha Agrawal

                    but then my problem remains same that i won't be able to inherit this control with TextBox so that all it's properties and events are avialable to the Control User. So now if there is any idea for this problem then i'll be really thankful to you.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    If you have a user control containing (say) a TextBox, you can make the required properties of the textbox visible by implementing them in the UserControl. Usually you wouldn't want the user of your control to have complete access to the textbox's properties - but certain properties can be exposed as you need...

                    public TxtBoxText
                    {
                    get {return textBox1.Text;}
                    set {textBox1.Text = value;)
                    }

                    and so on. So users of your control can use

                    myUserControl1.TxtBoxText = "WhateverIWantToSetItTo";

                    ___________________________________________ .\\axxx (That's an 'M')

                    N 1 Reply Last reply
                    0
                    • L Lost User

                      If you have a user control containing (say) a TextBox, you can make the required properties of the textbox visible by implementing them in the UserControl. Usually you wouldn't want the user of your control to have complete access to the textbox's properties - but certain properties can be exposed as you need...

                      public TxtBoxText
                      {
                      get {return textBox1.Text;}
                      set {textBox1.Text = value;)
                      }

                      and so on. So users of your control can use

                      myUserControl1.TxtBoxText = "WhateverIWantToSetItTo";

                      ___________________________________________ .\\axxx (That's an 'M')

                      N Offline
                      N Offline
                      Nisha Agrawal
                      wrote on last edited by
                      #10

                      Thats what i am thinking from starting but i was not sure that this is the only solution or it's a good approach. Thanks to you all.

                      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