|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Change the anchor property of a control.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 :) Am 12.06.2010 23:46, schrieb Mr. X.:
> Hello. Like I said, about once or twice, you should switch Option Strict On.> 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?) ? 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 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 :) 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 :) 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. Show quoteHide quote "Mr. X." <nospam@nospam_please.com> wrote in message news:OSB4qFsCLHA.5464@TK2MSFTNGP05.phx.gbl... > 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 :) > "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> wrote : I am using the PropertyGrid panel, and it has anchor on it - can I hide it ?> 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. 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 :) Am 12.06.2010 23:46, schrieb Mr. X.:
> How can I capture the event, when changing the anchor property of the There is no specific event, but you may want to take a look at the > control ? 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/> On Jun 13, 12:46 am, "Mr. X." <nospam@nospam_please.com> wrote: Hi,> 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 :) 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
Uninstall
Fueling your car with natural gas from home Create click event (keyboard key down) on Panel. Problem with query dates Inner class problem. VB copy files from one folder to other elearning info not working in dotnet ide can you return to previous position logging to text file and opening at end of program Creating an event by force. |
|||||||||||||||||||||||