How can I decrease the space between the controls even further?
I've set all the margins and padding to 0 but there is still space between my controlers.
this is the space I am getting with all margins and padding set to 0. I even set the margin and padding on each controller to 0.
and for the sake of consistency here is the code that is adding the PictureBoxes
Dim newPic As PictureBox = New PictureBox()
newPic.Image = p.Image
newPic.Size = New System.Drawing.Size(New Point(p.Size.Width * 2,
p.Size.Height * 2))
newPic.SizeMode = p.SizeMode
laytt.SetToolTip(newPic, ttstring)
AddHandler newPic.Click, AddressOf LayoutComponent_Clicked
LayoutFlowLayout.Controls.Add(newPic)
You are not setting the Margin property on the picture boxes you add. The default is 3,3,3,3. Add this line of code to fix the problem:
newPic.Margin = New Padding(0)
Every control handles margins differently, even with standard controls. Have a look at this example:
Notice that a Button reserves some space around it, while a TextBox takes everything. You may ask why 2 pixels in between them which you can clearly see. For that - please copy/paste into Paint and zoom in. Those 2 pixels are in fact the border, this is how a control is drawn. I am sure Buttons also have a border, but it's harder to justify visually, even when zoomed in.
If you want to change that, you would need to create a custom control and override how it's drawn, i.e. manually cut borders from it or similar. But I would not recommend doing it, to keep UI consistent.
Related
I am creating a Windows form using VB.net
The form is part of a VSTO Excel Add-in
I move the form to a secondary display using:
Dim b As Rectangle = activeScreen.Bounds
Dim location As Point = Me.Location
Me.StartPosition = FormStartPosition.Manual
location.X = location.X + b.X
location.Y = location.Y + b.Y
Me.Location = location
where activeScreen is of type System.windows.forms.screen.
Before resizing, my form is size {Width = 1139 Height = 308}
I resize my form using
Me.size = newsize
where new size has value {Width = 2278 Height = 308}
However, the value of Me.size somehow jumps to {Width = 5695 Height = 770}
And on the screen, this is in fact what is seen, the form is now 2.5 times bigger than what I expect.
If I change the height of the form in this way, all works fine. Similarly, the above code works fine when I keep my form on the primary display.
The value of Me.DeviceDpi is 96 in both scenarios.
My primary display is scale 250% (recommended) and Display resolution 3200x1800 in the settings, and screen bounds is [Bounds={X=0,Y=0,Width=3200,Height=1800}
The secondary display is scale 100% (recommended) and Display resolution 1360x768 in the settings, and screen bounds is {X=8000,Y=938,Width=3400,Height=1920}
The answer to this question seems to bear no resemblance to the problem.
I was resizing my form as part of a response to Form_PreviewKeyDownevent
Moving the code to Form_KeyUp event, suddenly everything behaved correctly as it had done when running on the primary monitor.
In the same vain, part of my form contains a Label that I change and move dynamically. This form was simply disappearing when I move the form to the secondary display. Debugging size, location, bounds etc showed numbers consistent with all the other controls on the form. Tried calling BringToFront() thinking maybe some subtle scaling had caused the label to be moved behind another control, but this did not help either.
Solution / workaround - every time I change or move the label, remove it from the controls and re-add a newly created label. Once again, with this work around, all once again works like it did on the primary monitor.
All,
If a TrackBar control on a Windows form is selected by mouse, the keyboard left/right arrow keys can be used to decrement/increment its value respectively. Unfortunately, selecting the control causes an unsightly focus box to appear around it.
I would like to override the control's ShowFocusCues() Property to hide the focus box but retain the ability to use the keyboard keys. The following code does not throw an error, but also does not return the result I wish to achieve. Please can you help?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myTrackBar As CustomTrackBar = New CustomTrackBar
With myTrackBar
.Top = 100
.Left = 100
.Width = 200
.Minimum = 3
.Maximum = 25
.Value = 7
End With
Me.Controls.Add(myTrackBar)
End Sub
End Class
Class CustomTrackBar : Inherits System.Windows.Forms.TrackBar
Protected Overloads Overrides ReadOnly Property ShowFocusCues() As Boolean
Get
Return False
End Get
End Property
End Class
I just would like to preserve keyboard functionality if doing so is straightforward
I don't doubt the way Jimi has suggested in the comments is more correct, but it's really straightforward to put a eg a 300x50 sized trackbar inside an eg 290x40 sized panel, positioned at -5,-5 so the focus box is visually cut off.
Note that I don't guarantee these pixel sizes are exact/correct so they should be regarded as "for illustration of the point purposes only"; I'm on a cellphone and cannot measure the image I created to demo this, but it looks like the focus rect is less than 5 pixels...
In this image the cutoff is more than 5 pixels - I deliberately positioned the trackbar so that part of the slider is cut off to demonstrate that controls inside panels, that overhang the bounds of the panel, have their visual area trimmed:
The form background is blue, the panel grey and the trackbar is yellow
add a panel to the form
set your trackbar background to red temporarily so you can see its bounds
drag the trackbar into the panel then drag it again to the top left corner
use the arrow keys eg 5 times in the up and left directions to push it
size the panel to the bottom right of the trackbar
hold shift and use up/left again to resize the panel down another 5 pixels in each dimension
if you're resizing this trackbar set the anchor properties appropriately on the trackbar and panel
revert the background
If you don't use anchor for resize/don't know how it works, it's simplest to consider it like:
Any edge that is anchored maintains the same number of pixels between that edge and the same edge of the container it is in. Controls try not to resize if they can
This means that anchoring left and right will cause a control to stretch if the window gets wider. Anchoring right only causes the control to slide as the window gets wider
I have a Windows form with a TabControl. In Tab 1 I have a RichTextBox (rtb1) and a Picturebox (pbx). In Tab 2 I have another RichTextBox (rtb2).
When I click a button, text from rtb1 and the current picture in pbx is put into rtb2. Problem is that the picturesize won't always fit. My current code is this:
Dim text = rtb1.Text
rtb2.AppendText(text)
Clipboard.SetImage(pbx.Image)
rtb2.Paste()
Is it possible to have the code resize the image as it's pasted?
It is possible to get the image from a windows path, I just didn't know how to resize this in a RichTextBox either. If this makes it easier?
Edit: This did it!
Dim newWidth = 500
Dim newHeight = 500
Clipboard.SetImage(New Bitmap(pbxDatasheet.Image, newWidth, newHeight))
rtbArmy.Paste()
Edit 2: It still doesn't work.
With the exact same code these things happen:
1. Most of the time the pasted picture(s) are the same size. But not the right size. I can change newWidth and newHeight all I want, they rarely differ in size. Although sometimes the picture is way larger than the others.
2. Sometimes it doesn't even add the picture to the RichTextBox. There's no pattern to when it happens.
The same lines of code can do all the above things. I have no idea what to do here.
I am having issues resizing a DataGridView in a VB.NET application. The DataGridView is not bound to a data source, as all data is entered into it manually.
It is currently docked in a TableLayoutPanel, set to Fill, and I would expect it to automatically resize to fit its assigned cell, but it seems to have a minimum size, at which I can not shrink it any further. This is a problem because the tablet PC I am deploying to has a much smaller resolution, so the Windows must scale properly. The TableLayoutPanels are keeping everything in the correct position, but it is crucial that my grids scale as well so that the end user can see the bottom scroll bar and all the records in the table.
This problem is pretty much the same as the one mentioned here.
If you go to AlternatingRowsDefaultCellStyle in the properties window of the datagridviewer there is Padding feature that defaults to 0,0,0,0 which represents each direction. Perhaps if you reduce the padding it will autosize up instead of being limited on the upper end moving down.
Use AutoSizeMode and FillWeight properties of columns in your datagridview
'Column 1
Dim columnindex As Int32 = Me.DataGridView1.Columns.Add("One", "One")
With Me.DataGridView1.Columns(columnindex)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.FillWeight = 80 'This can be used as percent value for column width
End With
'Column 2
columnindex = Me.DataGridView1.Columns.Add("Two", "Two")
With Me.DataGridView1.Columns(columnindex)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.FillWeight = 20
End With
Me.DataGridView1.Rows.Add({"sample text", "1"})
Me.DataGridView1.Rows.Add({"another sample text", "2"})
I have a word doc with a bunch of ActiveX Control buttons or whatever on it, and each time a button is clicked, a corresponding image needs to be displayed in a popup box.
I have a userform called ImageForm, and this is what I'm doing right now:
Sub Button_Clicked()
ImageForm.Picture = LoadPicture("appropriate_image_path")
ImageForm.Show
End Sub
Each of these images has a width of 8.5 inches, but their heights can vary anywhere from like 3 to 20 inches (they're snippets of a pdf). So I've set the width of the userform to a little more than 8.5 inches, and that looks fine. But I need to be able to scroll vertically through the image in the userform, since some of the images could be taller than a user's monitor.
I'm completely stuck on this. What I've tried so far is adding a frame to the form, then adding an image control inside the form, and setting the "ScrollBars" property of the frame to vertical. Then instead of using "ImageForm.Picture = ..." I use "ImageForm.ImageControl.Picture = ..." But it doesn't work.
Any insight here would be greatly appreciated. Hopefully this question is clear enough, I've only been using VBA for a month or so now. (I miss Java so, so much)
Thanks!
Here is a neat little trick based on one of my posts
The idea is to ensure that the image control is in frame control and the image control doesn't have a border. Also the image control's PictureSizeMode is set to fmPictureSizeModeClip so that we can scroll the image
SNAPSHOT (DESIGN TIME)
SNAPSHOT (RUN TIME)
CODE
Private Sub UserForm_Initialize()
With Frame1
'~~> This will create a vertical scrollbar
.ScrollBars = fmScrollBarsVertical
'~~> Change the values of 2 as Per your requirements
.ScrollHeight = .InsideHeight * 2
.ScrollWidth = .InsideWidth * 9
End With
With Image1
.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg")
.BorderStyle = fmBorderStyleNone
.PictureSizeMode = fmPictureSizeModeClip
End With
End Sub