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.
Related
I've got a MS Access form that contains a subreport.
This is to allow a sort of dynamic preview of what you are going to get when you launch the print (in fact it's a form that allows to chose among different print layouts).
Let's say that my report is this:
It has also non-fixed fields, but it's not relevant for this issue.
The report is quite small and when presented in the form I would like to apply some sort of zoom, which actually I can't find.
Even if the subform/subreport control is much larger than the report, there seems not to exist a property that allows you to resize the report.
The result is this:
I tried setting Default View to Print Preview, no changes in visualization.
I hoped that switching to Print Preview would allow a greater control of the zoom (like actually happens when you launch a 'standard' print preview).
I tried setting FitToPage to true.
I tried to set AllowReportView to force the Print Preview, with no luck. At this point i think Print Preview is simply not allowed in a report inside a form.
Is there some (or some other) way to address this smallness problem?
Thanks in advance
P.S. If zooming is not possible, I would at least highlight the real report area because showing only the borders of the subform/subreport control would be confusing in this case.
Correct, report on form can only be displayed in ReportView. I don't think you can get 'zoom' feature by any method. As for 'highlight' of report area, code could set Backcolor property of each report section when report loads, like:
Private Sub Report_Load()
With Me
If .CurrentView = 6 Then
.ReportHeader.BackColor = vbYellow
.ReportFooter.BackColor = vbYellow
.PageHeaderSection.BackColor = vbYellow
.PageFooterSection.BackColor = vbYellow
.GroupHeader0.BackColor = vbYellow
.GroupFooter1.BackColor = vbYellow
.Detail.BackColor = vbYellow
End If
End With
End Sub
Might want to set all controls with transparent BackStyle.
Or instead of setting Backcolor, use a background image (watermark) on report.
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 am using WindowsForms and I am trying to put a Textbox into my main menu and add an Image. However I cannot get the image to appear. What am I missing here.
txtRequestEdit.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
txtRequestEdit.Image = Properties.Resources.Wrench16 'This is a valid image.
txtRequestEdit is a System.Windows.Forms.ToolStripTextBox
EDIT- Here is an image of the menu. The item at the bottom of this menu is the txtRequestEdit control.
Strangely the no matter how you apply the image, it won't show on ToolStripTextBox. I think this is a bug because I found nothing about this behavior in the documents or on the web.
I will try doing this with a hack like owner-drawing the item or something else and will put the wrong answer here so the next person with this issue avoids this wrong path.
This is wrong:
Apparently the Image property "supports the .NET Framework infrastructure and is not intended to be used directly from your code.", so if (as you say) everything's OK and you've checked the image itself to be valid, using ImageList and ImageIndex may solve the problem (assuming the item lies inside a MenuStrip named menuStrip1:
txtRequestEdit.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
menuStrip1.ImageList = New ImageList()
menuStrip1.ImageList.Images.Add(Properties.Resources.Wrench16)
txtRequestEdit.ImageIndex = 0
I'm creating a label dynamically, and then adding text to it dynamically (and the amount of text added to it will be different each time). So, the label needs to always be the same width as the text inside it.
This happens by default when creating a label in the Windows Designer. But when creating a label dynamically, it appears to be "set" at a specific width, regardless of how much text is in it (which means that it often "cuts off" some of the text).
So... any idea how I can get the dynamically created label to always stay the same width as the text inside it?
If you want to do it manually, you can do something like this, every time you change the text:
Dim g As Graphics = Label1.CreateGraphics()
Label1.Width = CInt(g.MeasureString(Label1.Text, Label1.Font).Width)
However, it's much easier to simply set the label's AutoSize property to True and let the label do the work for you.
Label1.AutoSize = True
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