4
Answers

Problems with custom control

David Pereira

David Pereira

14y
4.1k
1
Hi everyone, I'm here asking some help:

I'm doing a very huge project with compact framework...and...thinking in give manutence in future, I realy need to program it in a good OO...and...the first problem is: I created custom class of TextBox, ComboBox, and others controls, with some propers changed for my default, like background in Gray, but, when I put there in the form, the IDE can't render in a TextBox, for exemple, showing the name of the class.

Creating this same thing in other smartdevice project, my code works, but in this one, something makes it don't...

since now I appreciate the help =)
Answers (4)
1
Jaish Mathews

Jaish Mathews

NA 7.3k 1.2m 14y

Attachment MyControl.rar


Hi,
I got your control rendered by following way. FYI, these are normal steps using in custom controls creation
  1. Created a new library project and added your class to that project. I additionally added a custom Button too.
  2. Added a project reference fom main winfrom project to my control project.
  3. Built the full solution
  4. Then added Control project library to tool box bhy rightclick->Choose Items->Browse.
  5. Now both of my controls [customized TextBox and customized Button] are visible inside the tool box.
  6. I just drag and drop. Now both controls are visible to me with specified properties.

Missed any of these steps? a separate project and adding that library to the tooll box and then only drag from the tool box.
More over whenever you are making changes to your control project, try to refresh the tool box too by re-browsing the library. 
Here attached my control project.
 
 
.
1
Jaish Mathews

Jaish Mathews

NA 7.3k 1.2m 14y

 
Hi,
In .net custom control, normally we are overriding the controls "Render" method and implementing our own logic.
So custom control can't see during design time. But it will be rendred during run time by executing our custom "Render" method mentioned above. Can you confirm these behaviours? or you are talking about UserControl?
 
 
0
David Pereira

David Pereira

NA 5 0 14y
Jaish, thx for your attenction

Unfortunately, my control didn't render even with your method (by the way, I liked so much)

I think it's some kind of configuration of the render...because in other project...starts from zero...it works...but...in this project that is already done...but need to change some controls...doesn't....


oh...btw...your .rar has 16kb...but...when I unrar...it's null inside Oo...anyway...I got the idea and implemented it =)
0
David Pereira

David Pereira

NA 5 0 14y
Hi Jaish, thx for the attenction

No, I'm not using a UserControl. I made a class named MyTextBox that extends TextBox (MyTextBox : TextBox)...

and the problem is...I just want to change some propers, like background, font color and size, and things like that, but, I will need to change this everytime that the client wants a new build, so, to help my part, I've done this...

and the problem goes on when...even after build the class...the render can't designer a textbox like other normal (but with my configuration)...

testing in a new project...this class works 100%...when I put a new item, it comes with the mask of a textbox normal and with my config that I programed...but...in this other...this doesn't work...the render just type me just myproject.MyTextBox ....and...if I need to change the position...lenght...or something like that...I don't have a reference to decide (all I see is that text) ...

to get better...there is no message of error to direct my efforts (compiling and running works like the other project....but in the VS don't =/ )

My entire code for the class is this:

class MyTextBox : TextBox //extending from TextBox
    {
        public MyTextBox()
        {
            base.Font = new Font("Arial", 10, FontStyle.Bold); // Changing the default value of the font
            base.BackColor = Color.Gray; // Changing the default value of the backcolor
            base.ForeColor = Color.Black; // Changing the default value of the forecolor
        }

        InputPanel ip = new InputPanel(); // Creating a InputPanel to show the virtual keyboard

        protected override void OnGotFocus(EventArgs e) // Showing the virtual keyboard when getting focus
        {
            ip.Enabled = true;
            base.OnGotFocus(e);
        }

        protected override void OnLostFocus(EventArgs e) // Hiding the virtual keyboard when losting focus
        {
            ip.Enabled = false;
            base.OnLostFocus(e);
        }
    }

thx for the attenction =)