PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Custom Control Design Mode Problem

 
 
=?Utf-8?B?TWF0dCBGaWVsZGVy?=
Guest
Posts: n/a
 
      5th Sep 2005
I have developed a custom control to be used in my application. My
application includes a form designer, so the control can be hosted while
designmode for the control is either true or false, depending on whether they
are using the form designer, or in "run mode". The custom control includes a
slider control that is supposed to be active in our form designer
(designmode=true) and inactive in our run mode (designmode=false). The
problem is that I'm getting the reverse.

I've put this code into an Intialize method that fires when the custom
control is instantiated.

Private Sub Initialize()
If Me.DesignMode = True Then
Splitter1.Enabled = True
Else
Splitter1.Enabled = False
End If
End Sub

This works in order to disable the splitter if the controls
designmode=False, but does not enable the splitter if the reverse is true.

I am working in VB.Net 2003.
 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      6th Sep 2005
Hi,

Thanks for your post.

Based on my understanding, your application implemented the IDesignHost and
other interfaces to introduce design-time support for hosting custom
controls.

Currently, I am not sure I understand your problem very well. It seems that
your program logic below is correct:

Private Sub Initialize()
If Me.DesignMode = True Then
Splitter1.Enabled = True
Else
Splitter1.Enabled = False
End If
End Sub

Do you mean that Me.DesignMode sometimes reports the wrong state? More
specificly, sometimes Me.DesignMode reports false in design-time, yes?

If we use Reflector to view Component.DesignMode, we will see:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
Browsable(false)]
protected bool DesignMode
{
get
{
ISite site1 = this.site;
if (site1 != null)
{
return site1.DesignMode;
}
return false;
}
}

So, Component.DesignMode just query the internal ISite and return its
DesignMode property. However, if site is not created, it will just report
false. For more information, please refer to the link below:
"Bug Details: DesignMode variable does not appear to work as expected"
http://lab.msdn.microsoft.com/Produc...x?feedbackid=d
6ad5162-9693-49cc-abc0-659111823582

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
 
Matt Fielder
Guest
Posts: n/a
 
      6th Sep 2005
Jeffrey,

Thank you for your reply. I'm sorry for the ambiguity of the first post,
but all of your assumptions were exactly correct. I did some checking, and
as you suspected, my control was not yet sited. I moved the code to the
method below, which is by both the resize and paint events of the control
(I'll figure which is best after it's working). I've monitored the output
windows during runtime, so I know the splitter is enabled, however I just
can't get it to activate when designmode=true. Is it possible that the
control while in design mode is not allowing focus to pass through, and if
so, do you have any suggestions for how to handle the problem?
Private Sub RedrawControls()
Dim ControlHeight As Integer = txtField.Height

If Me.ClientRectangle.Height <> txtField.Height Then
Me.SetClientSizeCore(Me.ClientRectangle.Width, txtField.Height)
Exit Sub
End If

If lblPrompt.Visible = True Then
txtField.SetBounds(lblPrompt.Width, 0, Me.ClientRectangle.Width -
lblPrompt.Width, lblPrompt.Height)
Else
txtField.SetBounds(0, 0, Me.ClientRectangle.Width,
lblPrompt.Height)
End If

If Me.DesignMode = True Then
Splitter1.Enabled = True
Debug.WriteLine(Splitter1.Enabled)
Else
Splitter1.Enabled = False
End If

End Sub

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Thanks for your post.
>
> Based on my understanding, your application implemented the IDesignHost
> and
> other interfaces to introduce design-time support for hosting custom
> controls.
>
> Currently, I am not sure I understand your problem very well. It seems
> that
> your program logic below is correct:
>
> Private Sub Initialize()
> If Me.DesignMode = True Then
> Splitter1.Enabled = True
> Else
> Splitter1.Enabled = False
> End If
> End Sub
>
> Do you mean that Me.DesignMode sometimes reports the wrong state? More
> specificly, sometimes Me.DesignMode reports false in design-time, yes?
>
> If we use Reflector to view Component.DesignMode, we will see:
> [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
> Browsable(false)]
> protected bool DesignMode
> {
> get
> {
> ISite site1 = this.site;
> if (site1 != null)
> {
> return site1.DesignMode;
> }
> return false;
> }
> }
>
> So, Component.DesignMode just query the internal ISite and return its
> DesignMode property. However, if site is not created, it will just report
> false. For more information, please refer to the link below:
> "Bug Details: DesignMode variable does not appear to work as expected"
> http://lab.msdn.microsoft.com/Produc...x?feedbackid=d
> 6ad5162-9693-49cc-abc0-659111823582
>
> Hope this helps.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      7th Sep 2005
Hi Matt,

Thanks for your feedback.

> I've monitored the output windows during runtime, so I know the splitter

is enabled,
Do you mean that you see the below Debug.WriteLine line outputs "true"
value?

If Me.DesignMode = True Then
Splitter1.Enabled = True
Debug.WriteLine(Splitter1.Enabled)
Else
Splitter1.Enabled = False
End If

>however I just can't get it to activate when designmode=true

I assume you mean that, although the Debug.WriteLine outputs
Splitter1.Enabled to be true, it still can not get any focus. This is your
concern, yes?

In the above statement, does the "designmode=true" mean DesignMode in
VS.net designer, or mean the DesignMode in your application design-time
support implementation? I suspect the latter.

Currently, because I did not have your runtime designer implementation
code, I can not understand what going wrong and can not give very useful
suggestion. But in design-time, the control's behavior is hooked by the
ControlDesigner associated with it. More specificly, Winform applied
System.Windows.Forms.Design.SplitterDesigner to Splitter control. I think
you can use Reflector to view the source code of
System.Windows.Forms.Design.SplitterDesigner to get more information of its
design-time behavior.

Normally, Splitter control shows focus through a design-time border
rectangle, which is drawn by SplitterDesigner.DrawBorder method.
SplitterDesigner.DrawBorder is called in SplitterDesigner.OnPaintAdornments
like this:
protected override void OnPaintAdornments(PaintEventArgs pe)
{
Splitter splitter1 = (Splitter) base.Component;
base.OnPaintAdornments(pe);
if (splitter1.BorderStyle == BorderStyle.None)
{
this.DrawBorder(pe.Graphics);
}
}

Its parent class method is: ControlDesigner.OnPaintAdornments, which is
finally called in ControlDesigner.WndProc with message: 15, that is
WM_PAINT for the control.

So you can follow this call stack to analysis why the focus border does not
appear in your application at "DesignMode".

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      12th Sep 2005
Hi Matt,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Matt F.
Guest
Posts: n/a
 
      12th Sep 2005
Jeffrey,

I am still unable to resolve the issue.

In answer to your question of::

In the above statement, does the "designmode=true" mean DesignMode in
VS.net designer, or mean the DesignMode in your application design-time
support implementation? I suspect the latter.

you are correct in assuming that the problem is while in design time support
within my application.

Then I get a bit lost in your suggestions. You suggest following a call
stack, by overridign OnPaintAdornments if I understand correclty, however
the application is in VB.Net and your suggested test code appears in C#.

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Matt,
>
> Does my reply make sense to you? Is your problem resolved? Please feel
> free
> to tell me, thanks
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      13th Sep 2005
Hi Matt,

Thanks for your feedback.

No, I did not mean to override the OnPaintAdornments method. Actually at
design-time, Splitter control's border is drawn by SplitterDesigner class
which attaches to Splitter control. Internally, SplitterDesigner draws
Splitter control border in SplitterDesigner.OnPaintAdornments method, I
then provide the source code for SplitterDesigner.OnPaintAdornments in C#(I
get this code from Reflector, you can also choose to view the code in
VB.net in Reflector).

Currently, I am not sure the root cause of your problem, so I suggest show
you the design-time Splitter control drawing call stack:
ControlDesigner.WndProc (WM_PAINT
)->ControlDesigner.OnPaintAdornments->SplitterDesigner.OnPaintAdornments
->SplitterDesigner.DrawBorder.

In normal situation, the border should draw well, but in your situation, it
seems that it does not draw, yes? So I suggest you add breakpoint in these
methods to see which method fail to call.

Just as I say in original reply, without reproduce out the problem, it is
hard for us to give a solution to resolve it. Can you narrow down the
problem into a little sample reproduce project? Then with this sample
project, I think I can understand the problem much better. Thanks for your
understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Matt F.
Guest
Posts: n/a
 
      13th Sep 2005
Jeffrey,

Thank you for your patience with me in dealing with this issue. I'm afraid
at this point I must show my ignorance in a couple of areas.

First, I assume that your reference to "reflector" is some sort of add-in?
If so, do you have information on where it is obtainable from?
Secondly, I obviously can see the call stack for my application, however
there is no reference that I'm seeing to the call stack for the splitter
draw --- if you could point me in the right direction to do this, it would
be appreciated.
Thirdly, I agree that this is a problem that would best be solved by
creating a much simpler project that breaks it down to the smallest possible
number of components, etc. However as I'm sure you are aware, the act of
implementing IDesignerHost is in no way a small task, which makes breaking
this out into a smaller set of code impractical.

What I have found that may or may not shed some light on the problem is the
..CanSelect property of the splitter is returning false, even though the
control is enabled, visible and .CanFocus is true. Unfortunately .CanFocus
is a readonly property --- do you have any idea what else might be causing
this property to return false?

""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Matt,
>
> Thanks for your feedback.
>
> No, I did not mean to override the OnPaintAdornments method. Actually at
> design-time, Splitter control's border is drawn by SplitterDesigner class
> which attaches to Splitter control. Internally, SplitterDesigner draws
> Splitter control border in SplitterDesigner.OnPaintAdornments method, I
> then provide the source code for SplitterDesigner.OnPaintAdornments in
> C#(I
> get this code from Reflector, you can also choose to view the code in
> VB.net in Reflector).
>
> Currently, I am not sure the root cause of your problem, so I suggest show
> you the design-time Splitter control drawing call stack:
> ControlDesigner.WndProc (WM_PAINT
> )->ControlDesigner.OnPaintAdornments->SplitterDesigner.OnPaintAdornments
> ->SplitterDesigner.DrawBorder.
>
> In normal situation, the border should draw well, but in your situation,
> it
> seems that it does not draw, yes? So I suggest you add breakpoint in these
> methods to see which method fail to call.
>
> Just as I say in original reply, without reproduce out the problem, it is
> hard for us to give a solution to resolve it. Can you narrow down the
> problem into a little sample reproduce project? Then with this sample
> project, I think I can understand the problem much better. Thanks for your
> understanding.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



 
Reply With Quote
 
Oliver Sturm
Guest
Posts: n/a
 
      13th Sep 2005
Matt Fielder wrote:

>This works in order to disable the splitter if the controls
>designmode=False, but does not enable the splitter if the reverse is true.


This is an issue that's been discussed on the web to no end. A nice
explanation is here:
http://weblogs.asp.net/fmarguerie/ar...23/395658.aspx

As to the workarounds - test carefully whether things really work for you.
I've seen several of the suggestions fail under specific circumstances,
none seems to be completely reliable in all situations.


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
 
Reply With Quote
 
Oliver Sturm
Guest
Posts: n/a
 
      13th Sep 2005
Matt F. wrote:

>First, I assume that your reference to "reflector" is some sort of add-in?
>If so, do you have information on where it is obtainable from?


Google is your friend: http://www.google.com/search?q=reflector


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Crashes in Normal Mode, Safe Mode With Networking mode butnot Safe Mode bhoi Windows XP Help 0 15th Aug 2011 10:05 PM
Different control theme in design mode and run mode Bartek Tatkowski Microsoft C# .NET 1 22nd Feb 2006 02:41 PM
Control Problem - Can't exit design Mode because Control cannot be created. =?Utf-8?B?V2lsbA==?= Microsoft Word Document Management 0 11th Feb 2004 11:51 PM
Re: Enter Excel Design Mode and Exit Design Mode Bill Lunney Microsoft Excel Programming 0 4th Aug 2003 07:48 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com Microsoft ASP .NET 0 1st Jul 2003 10:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 AM.