Forum  Commercial Foru...  Commercial Foru...  Few questions about custom control behavior
Previous Previous
 
Next Next
New Post 6/21/2012 5:27 AM
Unresolved
  wit205
53 posts
No Ranking


Few questions about custom control behavior 

I've created my custom, datetimepicker control and it acts really weird, so I have a few question.

First of all, what have i done:

 

public partial class MyDateTimePicker : Gizmox.WebGUI.Forms.DateTimePicker
    {
        public MyDateTimePicker()
        {
            InitializeComponent();
            this.ShowCheckBox = true;
            this.Checked = false;
            this.CustomFormat = " ";
            this.Format = DateTimePickerFormat.Custom;
            this.Height = 20;
            this.Width = 185;
            this.Update();
        }
        protected override void OnCheckedChanged(EventArgs objEventArgs)
        {
            if (this.Checked)
            {
                this.Format = DateTimePickerFormat.Short;
            }
            else
            {
                this.CustomFormat = " ";
                this.Format = DateTimePickerFormat.Custom;
            }
            this.Update();           
            base.OnCheckedChanged(objEventArgs);
        }
    }

 

the scenario is:

1. After creating MyDateTimePicker, rebuild solution, create new form, Drag and drop my control into the new form.

Questions:

a) Control MyDateTimePicker dropped into my form in fact has showcheckbox on true, checked on false customformat and format set. Do not have width and height set. Why ?

b) After compile and run control has these four first prop. set like in the constructor (so the field is empty), but as I said in a) - widht and height are not... and OnCheckedChanged event don't work too. Why? 

2. So... back to the code:  But... After compile, There is no event control anymore, and even by double-click I can't add "OnClick" event to my control. Here is the screen after compile and run:

 c) Why?

3. But I'm not giving up. I delete this control and drag and drop new one. Initial properties width and height still are wrong, but I have icon event. I add event OnCheckedChanged and leave it empty. Compile and run.

d) Everything is the same as in b), but OnCheckedChanged event. This event works fine as in overrided code. So.. is it a rule, that I have to add empty event when I ovrrided it ? this is my fourth question...

4. So, basiclly it works. Control is blank when check box is unchecked, and the date is shown when is checked. But! Now I want to change location and size manually in propeties. Back to code, change, move... compile and run. No changes.. Control is the same as I've created few minutes ago. I simply can't change size and location (I checked only these two properties).

e) so.. After setting size, location and adding event, after run the application... control is simply dead... For sure I can't change location of it anymore..  Why ?

5. Ok. Another try: Delete all from this Form and.. drag and drop my control. Set location and width first, then add empty event OnCheckedChanged, compile and run. And now finally it works.. control is right size, location, behavior. But ONLY, when I do this in right order.

6. Now I add second MyDateTimePicker. And I forgot to set size, location and events. Click compile and run... First control works great.. second not. So, I want to back to the code and correct this. Fail.. I can't add event now, and what's more interesting - there is no event control in my first MyDateTimePicker control. In runtime event works, but can't edit it or add new one. Double click on my first control (which has empty OnCheckedChanged  event, and works good) - just doeasn't work.. I can't and "onClick" event.

f) this is really really wierd... could you explain my this one ?

 

7. And the last one. I add MyDateTimePicker control. Set size, location.. add event, run, close etc etc... Now, I want to detele it from my form. Click on it. Detele. It's gone, but in Designer class there is still:

 

Controls.MyDateTimePicker myDateTimePicker1;

g) So, after delete I have to open Designer and detele it manually.

So.. I will be really really glad if somebody explain me some of these 7 questions ? Cause right now.. I think, creating custom controls in VWG is just mission impossible.
Thanks,

 

private

 
New Post 6/21/2012 11:26 AM
  palli
14323 posts
1st Level Poster




Re: Few questions about custom control behavior 
Modified By palli  on 6/21/2012 2:28:41 PM)

 Hi wit205,

I will try to answer your questions in order....

#1a : The height of the control is dynamically determined by the font size and you can see in the designer that you can't resize the control vertically, not even the base DateTimePicker control. Same behaviour as in windows forms.

When you set properties in the contstructor, these properties will hold when you dyamically create the control. When you use the designer, the designer has it's defaults too. You will see that designer default width being serialized (written) in the designer generated file which explains why the width isn't updated.

#1b: This is caused by the Visual WebGui optimizations in order to minimize any unnecessary communications between the client and the webserver. When a control is rendered on the client and there is no event handler registered for a particular event, no event handling code is rendered on the client. It is not the same to override the OnCheckChanged and registering an event handler for CheckedChanged. Instead of overriding OnCheckChanged, register the event and move your code there and you should be fine. 

#2: This is caused be a well known problem which has an open tracker entry here. You can usually lower the risk of this occurring by clicking SaveAll before you build and run, but in some cases you need to close the designer on that form and open it again.

#3: Already explained in #1b

#4: Not sure exactly what you mean here, unless it is explained by #2, in which case you should have two control instances written in the designer file. Take a look and see if you have an extra instance that is not added to the Controls collection.

#5 : I believe this has been explained in the sections above.

#6 : Without seeing your code, I would expect #2 would also explain this. Make sure to SaveAll, close designer and then build and run.

#7 : Again, most likely explained by #2. Not saving properly and closing down the designer before you build and run can do exactly that... adding some extra control instances to your designer file. 

Hope this explains but please let me know if I got something wrong or if I missed something out.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 6/22/2012 12:57 AM
  wit205
53 posts
No Ranking


Re: Few questions about custom control behavior 

Hi Palii,

Thanks very much. Basically #2 was the reason. So to make it clear.. Every time I do sth in Designer (by drag&drop or in code), I have to Save all and close designer. Then compile, run or just back into the "view code".. right ?

 
New Post 6/22/2012 3:35 AM
  JamesC
850 posts
www.redcastle.co.uk
1st Level Poster




Re: Few questions about custom control behavior 

Hi there,

when working with custom controls or user controls in order to prevent duplicated controls appearing in the designer I always create the controls in a totally separate Library project to the application then reference the library dll to use the controls in the application (NB referencing the dll not including the library project in the application solution)

This seems to work for me anyway and I do not get the duplicated control problem

cheers james

 
New Post 6/22/2012 9:12 AM
  palli
14323 posts
1st Level Poster




Re: Few questions about custom control behavior 

 Hi Wit,

You are welcome and thanks to James for his comment.

I have not thought in the line of what James suggested, so I can't really comment on that, but from what I have personally followed up on, and believe me I process hundreds of sample applications and code fragments every week, then the most major step to take is to click SaveAll before you run. 

Clicking SaveAll seems to prevent the majority of these issues from occurring, but not in totally all cases. Having the editor (the IDE) in view code mode doesn't matter either. What matters is really the UI Designer for the form or the control. Just make sure you click Save All and then close all UI designers before you run and you should only have occasional and very rare occurrences of this problem.

You could also follow the tracker entry I referenced to modify Visual Studio settings which should also take care of it, although I have not tried it personally. Modifying that setting does affect all Visual Studio designers if you change it, so I have not tested yet.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  Few questions about custom control behavior
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS