So I am making a small game in visual basics and at one of the thing I need to do is change the label size following an If statement. Sadly, It seemed way more complicated than I expected... I tried the following but it is "Read only"
If condition = false then
lbltmp.Font.Size = 12pts
end if
I also Tried the following based on my friends advise:
With lbltmp.font
.size = 12
end with
I found similar question but they were all in c#, Which I don't know how to code in yet
You need to change font instead of its size ;) See this: LINQ Cookbook, Recipe 1: Change the font for all labels on a windows form (Kit George)
label.Font = New Font("Comic Sans MS", 12, _
FontStyle.Bold Or FontStyle.Underline)
You have to write this code. This will change the whole property of label.
Yourlabel.Font = New Font("Font Name", 10, FontStyle.Regular)
You could actually change the size of it but you don't use code.
Instead just go to the properties of whatever you're trying to change the font size of, and go to the font property. Click on the 3 dots (...) and a box will open. In that box, you can change the font and its size too. So you could change the size there!
(by the way this is the first time I've given an explanation on a website.)
Related
I'm trying to create a form that allows the user to edit text on another form, however only the size OR style (bold, italic etc.) of the font is changed instead of both.
My current code:
fnt = Form1.Label6.Font
Form1.Label6.Font = New Font(fnt.Name, 12)
Putting FontStyle.Bold after means that size will only be bold. This is the same for regular and italic. I have a feeling I'm overlooking something simple but i just can't figure it out.
Thank you
I am trying to implement a 'Flag' w/ a menustrip.
I have an image list w/ a red flag and a black flag.
When I click the menu item, i want to toggle the image.
The problem I have is that once I change the image, it wants to do SizeToFit which makes the Icon roughly the height of text. I dont want that. I want the Image to be its actual size.
I have tried putting the statements in different orders, nothing i have tried seems to work.
Currently, I have the button set to the black flag at design time.
This code shows me trying to change to a Red flag.
tsbFlagPatient.Image = ilFlags.Images(1)
tsbFlagPatient.ImageScaling = ToolStripItemImageScaling.None
tsbFlagPatient.DisplayStyle = ToolStripItemDisplayStyle.Image
[If there is some better way to approach toggling the image, im open to that. That seems like a separate question. ]
I was unable to make ImageScrolling work.
Since I dont need text here, I used BackGround Image and set
BackgroundImageLayout = Stretch
This allows the images to be the right size.
You can turn AutoSize = false and then manually set Height, Width to fine tune your menu's size.
I did reconsider the ImageList and changed the images to being stored in the project Resources. This is the code to toggle the image
Public Sub SetFlagImage(flagSet As Boolean)
If flagSet = False Then
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_black
btnFlag.BackgroundImage.Tag = "black"
Else
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_red
btnFlag.BackgroundImage.Tag = "red"
End If
End Sub
This had no effect on the question posed here. In general, probably better than having an image list because all forms can access it.
I'm trying to make (using Visual Basic) a rudimentary questionnaire that measures multiple attributes and stores their values in an array and afterwards measures the attributes on a scale of 1 to 10.Now I've had the dumb idea to use a label for every single value of every attribute, and highlighting the right number by changing the label's image to yellow, instead of white(basically making the area behind the number a different color).
Now here's the issue: I can't seem to find out how to change a label's background image with code, which is what I'm asking. (I'm guessing the command should look something like "Label1.image = >image path<")
Pretty simple.
If text = No then
Label.Text = No
Else
Label.Text = Yes
End IF
You just have to change the text value of the label which is .Text = Text you want
And if your trying to show images, you should use the image control in the tool box, not a label
I have some code which changes all texts in a chart object to a specific size and font. Thing is the first time one runs the code it works like a charm. But if I change any part of the text within the chart and then re-run the code nothing happens.
E.g I run the code, then change the title heading to size 15 and font arial, then rerun macro, and nothing happens.
What can be wrong?
My code
With Selection
.Format.TextFrame2.TextRange.Font.Size = 10
.Format.TextFrame2.TextRange.Font.Name = "Times New Roman"
.Format.TextFrame2.TextRange.Font.Bold = msoFalse
End With
When you apply the fonts/sizes to the ChartArea in order to propagate them down to the individual pieces, Excel stores that info at the CharArea level. If you make a change to the one of the components (ChartTitle, Axis, etc.) and try to run your code again, there is no change on the ChartArea. Seems that Excel does not propagate those changes "back up". This makes sense since now the different items are styled differently.
The easiest way to deal with this is to reset the styles before you make your changes. ClearToMatchStyle applied to the Chart (i.e. ActiveChart or Selection.Parent in your context) will do it. It appears it will also make the change if you use a different font size or actually make a change to one of the ChartArea.Format properties (e.g. Size, Name, etc.).
Code for the reset option
ActiveChart.ClearToMatchStyle
With Selection
.Format.TextFrame2.TextRange.Font.Size = 12
.Format.TextFrame2.TextRange.Font.Name = "Times New Roman"
.Format.TextFrame2.TextRange.Font.Bold = msoFalse
End With
I have a strange problem and it's probably a simple fix, but after much research, I cannot seem to find a solution.
I have a DataGridView on which I'm trying to center the column headings, but the result is a left bias in the centering—almost like an indenting problem. I've seen a few posts on this issue on a site or two, but never a solution. Any thoughts?
Here's the statement I'm currently trying to use:
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
The code you've posted is on the right track: you need to set the ColumnHeadersDefaultCellStyle property of your DataGridView control.
However, you need to create a new DataGridViewCellStyle class and assign that to the ColumnHeadersDefaultCellStyle property. You can't modify the Alignment property as your code sample shows unless you have assigned a DataGridViewCellStyle class to this property.
So, for example, the following code achieves perfectly centered column headings in a blank project:
Dim dgvColumnHeaderStyle As New DataGridViewCellStyle()
dgvColumnHeaderStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
myDataGridView.ColumnHeadersDefaultCellStyle = dgvColumnHeaderStyle
In the future, you may find it easier to do these types of things from the Designer. If you still need to do it yourself through code, you can check the *.Designer.vb file that is created to see how it was done.
EDIT: I just now noticed the slight offset you're referring to in the columns—it does indeed create a little extra padding to the right of each header. It's not a bug, though. There's a much simpler explanation.
Like a ListView, the DataGridView supports sorting by columns. Therefore, each column header reserves enough space to display the sort glyph (usually an arrow) when calculating center justification.
If you want the column headers to be perfectly centered, you'll need to disable sorting. Set the SortMode property for the column to "NonSortable". This should prevent space from being reserved for the sort glyph whenever the column text is center or right justified.
If you want to center or use any other alignment style of the Column Header text you can use this
dgvResults.Columns("ColumnName").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter