From the post "Growing user control not updating"...
Using C#, .Net 2.0 in a Windows environment.
UserControl1 - draws cells to a bitmap buffer dependent upon NumberOfCells property
UserControl2 - panel contains UserControl1 which displays vertical scroll when necessary; also contains NumberOfCells which sets UserControl1's NumberOfCells.
Formf1 - contains NumericUpDown controls (just increments) which updates the UserControl2 - suppose to!
When I increment the control on the form by say 20, UserControl1 adds the necessary cells, UserControl2 displays the vertical scroll bar accordingly, BUT the form does not 'redraw' to the updated/correct image!! Meaning, after I increment by 20, cells are added, vertical scrool bar added... but the image shown is just everything else expanding.
I reset the control to scoll to the very TOP and the scrolling works, but the image is still staic... UNTIL I resize my form, more specifically, when I change it from maximize to window or vice versa!!!
What can I do to 'reset/redraw' the correct image???? Thank you in advance.
Lawrence
If this is C# and Windows Forms I would try calling Update() or Refresh() on the control to make it redraw itself.
Try calling Refresh in the Scroll events and the NumberOfCells Property.
Related
I am moving pictureboxes on a Form1 via left-clicking on them and dragging them to another position. (i.e., using mousemove, mousedown, mouseup with e.X and e.Y). I also connect lineshapes from one picturebox to another using drag and drop. When dragging the end of a lineshape, however, I don't show the end of the lineshape when it's over a picture box -- indicating that it's ok to drop on a given picturebox.
Question is, after moving pictureboxes to desired positions, there are times when the end of a dragged lineshape disappears over a "ghost" or remnant of a picturebox, which is no longer there. Apparently, the control positions need to be updated any time I move a picturebox. So, after I move pictureboxes around, is there some sort of refresh I need to do on the Form1's controls, so the positions of pictureboxes are updated?
Yes you need to make custom class that inherits panel/picturebox class and at constructor level you need to say me.doublebuffered=true to prevent shadow of dragging picturebox/panel
Also at your code in mouse moving event you need to subtract the current coordinates of the panel from your cursor coordinates to have the image near your cursor
I have a form with a floating gridview that must appear when filling a textbox or clicking on a button. If item selected or mouse leaving grid, grid becomes invisible so user can see rest of the form. Grid data most cases exceed maximum vertical size, so a vertical scrollbar is needed. My problem is that when mousing to vertical scrollbar triggers MouseLeave event, so grid becomes invisible.
This time I think it's not a code matter, so is there some property to change to make the program identify vscrollbar as part of the GridView? Or else is there some code solution to ignore MouseLeave event when mousing to scrollbar?
Here is my event code, pretty simple:
Private Sub GridCliente_MouseLeave(sender As Object, e As System.EventArgs) Handles GridCliente.MouseLeave
GridCliente.Visible = False
End Sub
Also, I'm using Component One C1TrueDBGrid instead of standard gridview. It may be important.
I found a solution to my problem by adding the GridView to a panel and changing the MouseLeaveevent to the panel. For this to work, the panel must exceed the GridView size at least one pixel each side, since MouseLeave will not trigger if GridView is the same size of the panel (you must mouse over the panel and not any other component inside it to have vb.net consider mouse inside panel). Maybe it's not the best solution but it works for me.
How can I arrange controls in my parent form by code?
So far I call the user controls with this code;
Me.ParentForm.Controls.Remove(Me)
controlMain()
I want the user controls arrange itself whenever the user resize the parent form or maximize the form. Currently, I set the controls by,
Public Sub controlMain()
Dim usrctl As New _ctlMain
_Main.Controls.Add(usrctl)
usrctl.Location = New Point(_Main.Width / 2 - usrctl.Width / 2, _Main.Height / 2 -usrctl.Height / 2)
End Sub
which is on a module. _Main is my parent form while _ctlMain is the control being called. I do not intend to put the user control on the parent form during design because I have other user controls to call after a specific function in an active control is called.
I have tried the autosize property of usercontrol but I guess it doesn't work on my application. Usercontrol doesn't have the dock and anchor properties.
Use one of the automatic layout controls, like a FlowLayoutPanel or a TableLayoutPanel.
Instead of adding your user controls to the form itself, add them to either a FlowLayoutPanel or TableLayoutPanel control that has been placed on top of the form using DockStyle.Fill.
It sounds to me like a FlowLayoutPanel is what you want. With that, the layout of the controls is handled entirely automatically, and they are positioned either in left-to-right or top-to-bottom order, depending on the value of the FlowDirection property.
The only reason to choose a TableLayoutPanel is if you need to have more precise control over the exact positioning of the controls. It works just like an HTML table, with each control getting its own "cell".
You can also set the Dock and/or Fill properties of the individual user controls if you'd like to ensure that their sizes are automatically adjusted. For example, you can set each control to fill the entire cell in which it is placed in a TableLayoutPanel.
My main form has two panels, left docked and right docked. The right side panel has two child panels with top dock and bottom dock settings. The usercontrol is added to the right side top panel.
My usercontrol has a panel and a label. The panel is anchored on all 4 sides, the label is anchored on all except the bottom. At runtime I create this usercontrol and set it to dockstyle=fill and then I add it to my top right panel.
With everything set to "fill" I expect that when I add my usercontrol to the panel it will take on the appropriate width and height and pass that info to the child controls (labels) inside of my usercontrol.
My problem is that this stretching of the size does not happen when I create my objects during the Load event on my usercontrol. Even though initializecomponent has ran for the usercontrol the panel inside of it (4 corners anchored) has not taken the x/y values of the available space. As a result my usercontrol shows up about 50% of the width I want.
Lets say that instead of creating objects during usercontrol load that I instead start a timer and have the timer call my create routine when it raises the tick event. When I do things like this my objects are created with the full width/height that I expect. The only issue here is that this causes a delay in my interface.
Can someone help explain this behavior? My mainform is calling a "load gui" routine which is instantiating usercontrols, setting panel sizes, and then adding usercontrols to those panels. This particular user control is the last to load into the panels from that load gui routine so it does not make sense that the parent panel width/height would not be known yet. This is one of my first apps where I am purposely trying to use dockstyle=fill to keep things consistent across different main form sizes without writing all the extra size_changed code handlers. I'm sure this one is easy to work around once I know where the problem lies.
Thanks for any help provided!
this turned out to be a padding issue on the parent usercontrol. I also had to allow a bit of wiggle room to make sure that the controls didn't overflow the panel so I did a parent.width - 15 and that along with the padding made everything work much better.
Sometimes, I have a picturebox lets say 100x100. But the image it will display is actually 100x400.
I don't want to increase the size of the picturebox itself. Instead, I would like to create a vertical scrollbar (or horizontal if needed).
I could not find a scrollbar in the toolbox, so I guess I have to code it. But, how?
And I still wonder if I didn't make a mistake and didn't see the scrollbar in the toolbox. My apologies then :(
I suppose you could add separate scrollbar controls and sync their Scroll events up with the offset at which the picture in the PictureBox is drawn, but that sounds like actual work. There's a better way.
Add a Panel control to your form, and set its AutoScroll property to "True". This will cause the control to automatically show scrollbars when it contains content that lies outside of its currently visible bounds. The .NET Framework will take care of everything for you under the covers, without you having to write a single line of code.
Drag and drop your PictureBox control inside of the Panel control that you just added. The Panel control will then detect that one of its child controls is larger than its visible area and show scrollbars, thanks to the AutoScroll property. When the user moves the scrollbars, the portion of the image in your PictureBox that is visible will be automatically adjusted. Magic.
(The reason you have to use a Panel control as a container is because PictureBox does not inherit directly from the ScrollableControl base class, which is what provides the AutoScroll property.)
I tried this and it worked well. But I noted that if the picturebox is docked in the panel, the picturebox is automatically set to the size of the parent panel, and can't be set larger (at least not in any way I could find). This defeats the purpose of the technique. So -- put the picturebox on the panel, but don't dock it, and it will work perfectly.
There are no automatic scroll bars on a picture box, but you can add the VScrollBar (and HScrollBar) control to the form and handle the image scrolling manually by redrawing it at a different offset each time the Scroll event is fired.