473,409 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Custom Control Design Mode Problem

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.
Sep 5 '05 #1
10 5451
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(DesignerSerializat ionVisibility.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.

Sep 6 '05 #2
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]"" <v-*****@online.microsoft.com> wrote in message
news:Ct**************@TK2MSFTNGXA01.phx.gbl...
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(DesignerSerializat ionVisibility.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.

Sep 6 '05 #3
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.

Sep 7 '05 #4
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.

Sep 12 '05 #5
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]"" <v-*****@online.microsoft.com> wrote in message
news:3H*************@TK2MSFTNGXA01.phx.gbl...
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.

Sep 12 '05 #6
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.

Sep 13 '05 #7
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]"" <v-*****@online.microsoft.com> wrote in message
news:z7**************@TK2MSFTNGXA01.phx.gbl...
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.

Sep 13 '05 #8
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)
Sep 13 '05 #9
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)
Sep 13 '05 #10
Hi Matt,

Thanks for your feedback.
First, I assume that your reference to "reflector" is some sort of add-in? No, Reflector is a .Net decompiler writen by Lutz Roeder, it can be used to
view the souce code of .Net Framework. It is really a must have tool for
.Net developer :-), the below is the download link:
http://www.aisto.com/roeder/dotnet/
Secondly...
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.

Yes, this is by design. If you view Control.CanSelect property in MSDN, you
will see the following statement:
"The Windows Forms controls in the following list are not selectable and
will return a value of false for the CanSelect property. Controls derived
from these controls are also not selectable.
...
Splitter
....."

However, I do not think this has anything to do with our problem.
Splitter.CanSelect is a design-time behavior, and it is by design for not
selectable. In our scenario, the problem is that at designtime, when the
Splitter control is enabled, when it has focus, it does not draw a design
time focus rectangle, yes?
If we view Splitter control in VS.net designer, we will see that when it
has focus, a normal design focus rectangle will appear as its border. This
is actually not drawn by Splitter control, it is actually draw by the its
associated SplitterDesigner.(SplitterDesigner is not a public documented
class, we can just see it through the Reflector). So we should move our
focus in this SplitterDesigner class, not the Splitter control(because we
are at design-time, aren't we?) So I suggest you add a breakpoint in
certain method of SplitterDesigner class(Note: we have to setup the
debugging symbols correct, debuggin symbol is critical for the debugging
session, more specificly, we should set a environment variable like this:
_NT_SYMBOL_PATH=srv*C:\Symbols*http://msdn.microsoft.com/download/symbols;
For more informaiton, about how to setup symbol for debugging, please refer
to: http://www.codeproject.com/debug/windbg_part1.asp)

After setting up the symbol, we can add breakpoint for .Net method with
"New BreakPoint" dialog, for example, input the following method:
System.Windows.Forms.Design.SplitterDesigner.OnPai ntAdornments

After the breakpoint is hit, we can get the SplitterDesigner invoking call
stack through "Call Stack" debugging window in VS.net.

Hope this information 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.

Sep 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Samir Patel | last post by:
Hi Everybody hai i am fine what about all of u? i have a problem regarding to ASP.NET custom control , can anybody help me? my problem is when i placed my custom control on page at design...
11
by: Brian W | last post by:
Yet another editor problem To reproduce do the following 1) Open a Webform and switch to HTML edit mode 2) Enter the Following (include spaces) This is some text before <asp:hyperlink...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
10
by: Matt Fielder | last post by:
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,...
3
by: Tabi | last post by:
Hi, I have just created a class that removes action attribute from HtmlForm. The code looks like here. namespace ComIT.Applications.Common { public class Form :...
4
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
1
by: xamman | last post by:
i have the same problem as this earlier post (unfortuneately he never received a reply) any suggestions? thx I'm trying to create a web custom control. I've worked in asp.net extensively, but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.