PC Review


Reply
Thread Tools Rate Thread

Change the anchor property of a control.

 
 
Mr. X.
Guest
Posts: n/a
 
      12th Jun 2010
Hello.
How can I capture the event, when changing the anchor property of the
control ?

I.e :
myPanel.anchor = AnchorStyles.Left & AnchorStyles.Bottom
....
How can I know, when the Anchor property is changed (which event?) ?

Thanks

 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      12th Jun 2010
Am 12.06.2010 23:46, schrieb Mr. X.:
> Hello.
> How can I capture the event, when changing the anchor property of the
> control ?
>
> I.e :
> myPanel.anchor = AnchorStyles.Left & AnchorStyles.Bottom
> ....
> How can I know, when the Anchor property is changed (which event?) ?



Like I said, about once or twice, you should switch Option Strict On.

Then, why do you want to have an event? There is no such event, and there
is no overridable method that is called when the property changes (like
'OnAnchorChanged'). I would handle the Resize event instead. Whether the
control is anchored or not shouldn't matter.

If you set the property like above, you know where the value changes.


--
Armin
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th Jun 2010
Am 12.06.2010 23:46, schrieb Mr. X.:
> How can I capture the event, when changing the anchor property of the
> control ?


There is no specific event, but you may want to take a look at the
control's 'Layout' event and 'OnLayout' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      13th Jun 2010
A little problem, and I shall explain the meaning of my program :
----------------------------------------------------------------------------------
I am creating a min-ide screen (I can drag and drop on it some components,
with no events on them : only design).
1. I don't want that the components will act as a real component (there
should not be event on it, when pressing mouse-click, for example).
(disable the events, when clicking - If I knew that, it would solve many
problems).
2. I want to capture some layout events.

It may be a bad solution, but far as I have found yet is :
1. I have created an ide with handles, so I can drag and drop component,
move them, stretch them, etc.
For that I made two controls :
First one is the "visual control" (that has no parent control, but "knows"
how to draw the control (but is not paintable on screen).
Second one is an "active control", which is a pictureBox, that is paintable.
When changing some properties on the first one, such as color, text, etc. I
move the "image" from the first one to second control,
by DrawToBitmap method.
2. For some layout (only layout), because the first control is invisible
one, I capture its event (such as DockChanged, resizing and moving),
and checking the delta of width, height, etc. (For DockChanged - when this
occurred on first control, I do the same for the second one, and do some
changes on width, height, top, left, by checking the deltas).
3. Also, I am using propertyGrid control, that is connected to the first
control (named "active control").
4. Everything works fine, and good, but the only thing that I cannot handle
when anchor is changed.
Solution for that, I think :
4.1. Giving up the anchor property and hide it on property grid (how
doing that ?).
4.2. Changing the first control behavior, that it should act as a
control for design time only.

Summary (Major questions) :
==================
1. Need an elegant solution, and knowing whether my solution is bad or good.
2. How can I "disable" the events on the control (and alow only some
events), so the events won't occur when running my code (such as button
click. There are 10 different components I can drop on screen) ?
3. How can I give up and hide some properties on the propertyGrid control?

Thanks

 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      13th Jun 2010
O.K.
Solved !!!
I have solved the above, by keeping the old anchor, and every time when the
event :
properyGrid.SelectedGridItemChanged, I am checking whether the old anchor
has changed.
If it is changed, then I move the same anchor from the first control to the
second one.
That's solved the problem, and I can keep on ...
If you have any other comments on my approach, I would like to know about.

Thanks, anyway

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      13th Jun 2010
Why then do you set that anchor.
You can remove it completely in my idea.

In my idea is for your solution panels and docking more used.


"Mr. X." <nospam@nospam_please.com> wrote in message
news:(E-Mail Removed)...
> O.K.
> Solved !!!
> I have solved the above, by keeping the old anchor, and every time when
> the event :
> properyGrid.SelectedGridItemChanged, I am checking whether the old anchor
> has changed.
> If it is changed, then I move the same anchor from the first control to
> the second one.
> That's solved the problem, and I can keep on ...
> If you have any other comments on my approach, I would like to know about.
>
> Thanks, anyway
>

 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      14th Jun 2010
"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote :
> Why then do you set that anchor.
> You can remove it completely in my idea.
>
> In my idea is for your solution panels and docking more used.

I am using the PropertyGrid panel, and it has anchor on it - can I hide it ?
Besides, I have overcomed the anchor problem.
I need the propertyGrid for the most of the propeties (colors, borders, etc
....).
All the layout, and position - I am doing by hands in the hard way.

Now - I try to overcome setting parent-child relations as it should be set
(panel that has some controls on it).

Thanks

 
Reply With Quote
 
Onur Güzel
Guest
Posts: n/a
 
      14th Jun 2010
On Jun 13, 12:46 am, "Mr. X." <nospam@nospam_please.com> wrote:
> Hello.
> How can I capture the event, when changing the anchor property of the
> control ?
>
> I.e :
> myPanel.anchor = AnchorStyles.Left & AnchorStyles.Bottom
> ...
> How can I know, when the Anchor property is changed (which event?) ?
>
> Thanks


Hi,

Though there's no built-in event like OnAnchorChanged, however you can
still write your own event and sync it with the original anchor
property behind the scenes. The key part is that you have to assign
anchor property to your own property like named "PropGrid1Anchor",
rather than native Control.Anchor at runtime, like in the example
below.

Place this into your existing Form class code:

'--------------------------------------------------------------------
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

' Change our custom anchor property to see it raised
Me.PropGrid1Anchor = AnchorStyles.Right _
Or AnchorStyles.Bottom

End Sub

Public Event PropGrid1AnchorChanged(ByVal sender As Object)

Public Property PropGrid1Anchor() As AnchorStyles
Get
Return Me.PropertyGrid1.Anchor
End Get
Set(ByVal value As AnchorStyles)
' It will also set built-in anchor property
Me.PropertyGrid1.Anchor = value

' Let it raise
RaiseEvent PropGrid1AnchorChanged(Me)

End Set
End Property

Public Sub PropGrid_AnchorChanged _
(ByVal sender As Object) _
Handles Me.PropGrid1AnchorChanged
' Test it
MsgBox("Raised!")
End Sub

'--------------------------------------------------------------------
Note that you're assigning anchor property to specific instance of
PropertyGrid control, that is PropertyGrid1. You can customize it in
order to your needs. There may be other thoughts, but also it can be
an option to evaluate.

HTH,

Onur Güzel
 
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
anchor property =?Utf-8?B?YWlkaW1vcmluaQ==?= Microsoft Dot NET 0 9th Oct 2006 02:16 PM
how do I change the href property to the web anchor element =?Utf-8?B?ZXN3YW5zb24=?= Microsoft ASP .NET 6 28th Mar 2006 10:35 AM
Anchor Property Ignored On Custom Composite Control =?Utf-8?B?SmFtZXM=?= Microsoft VB .NET 0 23rd Jun 2004 10:14 AM
Anchor Property.. VJ Microsoft VB .NET 2 24th Mar 2004 09:35 PM
Anchor Property CJ Taylor Microsoft VB .NET 4 10th Sep 2003 07:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 AM.