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. window forms control is automatically deleted

window forms control is automatically deleted

Scheduled Pinned Locked Moved C#
helptutorialquestioncsharpdotnet
4 Posts 2 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.
  • T Offline
    T Offline
    Tony_Joh
    wrote on last edited by
    #1

    Hello! I have a very specific question and that is about how to inherit a control for example the control System.Windows.Forms.TextBox without causing the environment to delete the control when there are some compile errors. It's the same problem with any visual control that you inherit. The control is deleted as soon as you use the View Designer when there is compile error. It's very easy to reproduce my problem. You can do it in this way. 1. Create a class called ExtTextBox like this. In my example here I have removed the namespace. But if you include namespace make sure you have access to it. public class ExtTextBox : System.Windows.Forms.TextBox { public ExtTextBox() {} } As you can see this class ExtTextBox inherit from the ordinary components System.Windows.Forms.TextBox in the .NET framework 2. Create a windows form with any name. The default is Form1 3. Use the View Designer and create the control TextBox in the window form. My control was called textBox1 4. Because I want the control textBox1 to be an instance of ExtTextBox I have to edit the InitializeComponent() I don't have any other idea. Here is an extract from my windows form called Form1. Only the interesting rows is written. Two rows are important here. First saying that control textBox1 is of type ExtTextBox. Second edit the InitializeComponent and say that textBox1 is an instance of ExtTextBox. public class Form1 : Form { private ExtTextBox textBox1; // First saying that control textBox1 is of type ExtTextBox. ... ... ... Private void InitializeComponent() { //Second edit the InitializeComponent and say that textBox1 is an instance of ExtTextBox this.textBox1= new ExtTextBox(); ... ... ... } } 5 Compile. Hopefully you don't get any compile errors. When you run the application only the textBox is being displayed. The problem might start even here. If you get any compile error and you use the View Designer the control named textBox1 is being deleted automatically. 6 If you don't get any compile error make a change so you get a compile error and then use the View Designer the control named textBox1 is being deleted automatically. 7 Now to my question. I can't use controls that being deleted automatically when I get compile error. 8. If I want to use inheritance on visual control how do I do. I just can't have it as it is now. 9 I just can't use inheritance in the way I do now. 10. I hope that you have a

    E 1 Reply Last reply
    0
    • T Tony_Joh

      Hello! I have a very specific question and that is about how to inherit a control for example the control System.Windows.Forms.TextBox without causing the environment to delete the control when there are some compile errors. It's the same problem with any visual control that you inherit. The control is deleted as soon as you use the View Designer when there is compile error. It's very easy to reproduce my problem. You can do it in this way. 1. Create a class called ExtTextBox like this. In my example here I have removed the namespace. But if you include namespace make sure you have access to it. public class ExtTextBox : System.Windows.Forms.TextBox { public ExtTextBox() {} } As you can see this class ExtTextBox inherit from the ordinary components System.Windows.Forms.TextBox in the .NET framework 2. Create a windows form with any name. The default is Form1 3. Use the View Designer and create the control TextBox in the window form. My control was called textBox1 4. Because I want the control textBox1 to be an instance of ExtTextBox I have to edit the InitializeComponent() I don't have any other idea. Here is an extract from my windows form called Form1. Only the interesting rows is written. Two rows are important here. First saying that control textBox1 is of type ExtTextBox. Second edit the InitializeComponent and say that textBox1 is an instance of ExtTextBox. public class Form1 : Form { private ExtTextBox textBox1; // First saying that control textBox1 is of type ExtTextBox. ... ... ... Private void InitializeComponent() { //Second edit the InitializeComponent and say that textBox1 is an instance of ExtTextBox this.textBox1= new ExtTextBox(); ... ... ... } } 5 Compile. Hopefully you don't get any compile errors. When you run the application only the textBox is being displayed. The problem might start even here. If you get any compile error and you use the View Designer the control named textBox1 is being deleted automatically. 6 If you don't get any compile error make a change so you get a compile error and then use the View Designer the control named textBox1 is being deleted automatically. 7 Now to my question. I can't use controls that being deleted automatically when I get compile error. 8. If I want to use inheritance on visual control how do I do. I just can't have it as it is now. 9 I just can't use inheritance in the way I do now. 10. I hope that you have a

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      Which version of VS.NET are you using? If it's 2005 then the custom control should be available in the toolbox. If it's 2002 or 2003 I'll try and have a look at it but I can't remember since I havn't done any dev work on them in the last 6 months or so. But I seem to remember coming across this problem. The easiest solution I seem to remember I found was to create a new project (where possible) for containing these custom controls and reference this from the application. I know this isn't as clean a solution but it was the most reliable. Ed

      T 1 Reply Last reply
      0
      • E Ed Poore

        Which version of VS.NET are you using? If it's 2005 then the custom control should be available in the toolbox. If it's 2002 or 2003 I'll try and have a look at it but I can't remember since I havn't done any dev work on them in the last 6 months or so. But I seem to remember coming across this problem. The easiest solution I seem to remember I found was to create a new project (where possible) for containing these custom controls and reference this from the application. I know this isn't as clean a solution but it was the most reliable. Ed

        T Offline
        T Offline
        Tony_Joh
        wrote on last edited by
        #3

        Hello!! Thanks for your answer. I use VS 2003. I can't understand how your solution can solve my problem. Can you be be specific. //Tony

        E 1 Reply Last reply
        0
        • T Tony_Joh

          Hello!! Thanks for your answer. I use VS 2003. I can't understand how your solution can solve my problem. Can you be be specific. //Tony

          E Offline
          E Offline
          Ed Poore
          wrote on last edited by
          #4

          What my work-around was was to create a new project (within the same solution) for containing the controls. So you'd have e.g. Application.csproj contained in Project.sln, if you create a Controls project in your solution to contain the controls. Then when you want to put them on the form VS2003 should have automatically added a toolbox entry for the control. If not you can add it to the toolbox manually. (Sometimes if an you've updated the custom control you may need to remove the assembly which contains the control from the debug/release folder of your project to force VS to get a new copy) Ed

          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