How do I create an image button? - mouseevent

I'd like to display an image which acts as a button. This means that when I click on the image a mouseUp handler is executed.
image area does not have a mouseUp handler
the buttons seem not to have a property where I can assign an image to them.

You can add a mouseUp handler to an image's script, and it will be triggered when the image is clicked:
on mousedown
answer "hi"
end mousedown
You can give a button an image by setting it's "icon" property to the id of an image on the stack (you will generally then want to unset the 'opaque', 'threed', and 'shadow' properties in order to make it look pretty).

What David said.
Though "mouseUp" is introduced as a natural button-related handler, be aware that any object can have such a thing, including a field if it is locked, and there are even ways around an unlocked field as well. The important thing is to know that the language and its environment are far broader and richer than you might at first infer from the tutorials and lessons.
Craig Newman

You can assign icons to buttons. This solves all your problems at once.
Create a new image control, e.g. by importing an image using the File menu. Create a new button and set the icon of the button to the id of the image control. If you like, you can use another image control for the hilitedIcon of the button. Add mouseUp and mouseDown handlers to the button as desired.
If the image is too big, resize the button to make the image fit. Set the showName of the button to false or change the margins (something like 0,32,0,8) to move the text below the icon.

Related

In VC++ 2013, dialog boxes damage PictureBox contents (drawing)

I cannot find how to protect a drawing in a PictureBox control from being corrupted (wiped out) when I call a dialog to save the form or print it out. The form is saved or printed out OK, but the dialogs wipe out most of the PictureBox drawing after they leave. Yet the buttons and progress bar on the form are restored OK -- so there must be a way to 'protect' the PictureBox drawing as well. How is it done?
The reason is that you need to repaint the picture box after the dialog has gone away.
Your picture box will get a Paint event, that will tell you that you need to do some re-drawing.
In there, use the supplied graphics contexts etc to draw on the picture box again. Probably you will want to write a separate method that does drawing, and call it for an initial view, and also during that paint. But that's up to you.
If you will always have olny one picture in your PictureBox, or you will be always using pictures with of same size you can just override OnEraseBkgnd function for this control and return TRUE on exit of this function.
This way content of your will not be altered by unplanned OnPaint or OnEraseBkgnd calls.

Objective C image click action

I have seen this in other programs and am trying to replicate it.
I have an image on one of my forms that someone can drag-and-drop an image into. I would like to allow the user to click on that image to pop up another dialog that they could instead select a "stock" image if they choose to.
I don't see an outlet I can use for the click and putting a transparent button over the top would defeat my ability to drag and drop an image on to it.
I realize I could just change the image to a button instead but I prefer to use an image if possible.
How can I make an image clickable?
This is OSX by the way, not IOS.
Quoting from another question:
By default, NSImageView doesn't react to -mouseDown:, or -mouseUp: like other NSControl subclasses (namely NSButton) do.
The solution is given in an answer elsewhere - subclass NSImageView and appropriately handle the click event (as linked).
Drag in the standard NSButton.
Uncheck the Bordered checkbox.
Clear the Title text.
Set the Image (and optionally, the alternate image).
Also, if you are using layout constraints to set button size to image view size, don't forget to set vertical hugging/compression resistance priorities to low values (say 1).

maximize listview when form window is strteched at runtime

I am using vb.net, I have created a form and there are two listviews in that form which are getting filled by button event. Every thing is going smooth, but the problem is when my exeute my project and in the form, when I maximize the form window(by clicking maximize button provided in the top right corner) the size of listview remains same while form maximizes, this looks odd, what i need is to maximize the listview also with the increase in the form window size.
I searched in google a lot and i found one property 'dock' of listview which i can set left, full, right,bottom,top or none, but this doesn't serve my purpose.
Snapshot when I am using Anchor property
On Starting:
After Maximizing:
Please guide me in the right direction, what I need to do
when no propety is set then image on maximizing is:
Thank you
With Regards
Better than Dock property, you have to use "Anchor" property. All controls on the Form has Anchor Top,Left by default, but you can change it in the property window or directly by code. You can know more about anchor on this site: http://www.homeandlearn.co.uk/NET/nets13p1.html
Anchoring two Listviews on a form depends on the form design, but SplitContainer control will be really usefull if you want that both Listview changes the size on form resize.

Want To Create A Floating Speech Bubble Form

Wondering if someone could help me....
I have a small .NET application where I have an Edit button on a main form. When the user clicks the Edit button, I want to popup a small form right next to it (on top of the main form) with a speech balloon tail attached on the side of the form pointing to the Edit button. So it gives the effect of a floating form pushed out from the Edit button.
I don't want the appearance of a normal speech bubble, I want it to look like an actual borderless form (with square corners). It could be a custom control or anything (however, I am not yet familiar with creating my own custom controls), but I need to add Text Controls, Pictures, Label Controls, etc. to this floating form.
Any help would be appreciated.
Thanks
UPDATE
I am trying to create something to this affect:
So imagine the ? being the Edit button and the other being a form with custom controls.
Like this?
To get this behavior:
Select an image which will represent your speech bubble. Put a PictureBox on the form, make it use this image. Place two labels, as above, adjust the font.
Pick your transparency key (color). Your image background and form background need to be set to that. I used black for demo purposes, which is a bad choice if you plan to have any black or text in your speech bubble. Set form's TransparencyKey property to this color in designer. More about TransparencyKey on MSDN.
(final step, not shown on the screenshot). Set FormBorderStyle = None.
Also make sure you have other ways to close your bubble, because X will be unavailable.
The final result may look something like the following:
Note: You may notice some drawing artifacts, most images on the internet have smooth borders, and transparency key does not support shades, has to be exact color. If you are fine with these minor artifacts, feel free to leave it at that. Or, edit it to get rough borders. Or find another one that better suits your needs.

How can I show scrollbars on a PictureBox control?

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.