How to change one image with another on click and back it again on release in Delphi? - image

I made a set of images of piano keyboard, all in two versions - one white and second with red color. I lined all keys pictures up next to each other, first white keys, then red over them. Now I would like to hide red ones, and they need to show only when it's clicked on the certain white key, so it's needed to visually show as if it were pressed. Then back to white when it's released.
I'm also interested doing it with my midi keyboard as well, so wonder how to achieve this with midi data?
Thanks

How to achieve this depends on what Controll you use for showing the button.
If you use TImages then use OnMouseDown (http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.Controls.TControl.OnMouseDown) and OnMouseUp (http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.Controls.TControl.OnMouseUp) events.
In OnMouseDown you turn your Piano Key color to red.
In OnMouseUp you turn your Paino Key color to white.
If you decide for this approach you might also need to handle special case (user moving mouse away from key while mouse button bein pressed down).
You could achieve this with OnMouseLeave (http://docwiki.embarcadero.com/Libraries/XE7/en/Vcl.Controls.TControl.OnMouseLeave) event in which you check to see if your Piano Key is red and then change it to white.
As for general aproach for switching between pressed and unpressed key versions don't change their positions by brnging them to front or sending them back as this would screw up the clicking detections of your controlls (by default the topmost detects clicks).
Instead use one set of controls and change their image at runtime.
If you have any expirience with creating custom components you could quickly create one which will have two states and two images one for each state. So in the end you only switch between two states either with ckicks or with code.
If you don't have expirience with creating custom components please tell which components you use now and I can try making a custom version of that component with the above mentioned functionality for you.

Related

Event for Markup drawing

What is the name of event when we start drawing the markup(circle, arrow, rectangle etc.) on the shape when in edit mode? And can we change the markup type in this event?
Problem is: When we are in edit mode and have selected specific shape and color to draw the markup, and in between if we select any markup, the drawing tool takes up that shape and color for the next markup to be drawn ignoring the markup type and color we selected earlier. Is this the normal behavior. Why does the drawing tool take up the configuration of the last selected markup and overrides the type we define through - new Autodesk.Viewing.Extensions.Markups.Core.EditModeCloud(markupExt);
Thanks!
That's an interesting question. I believe the current behavior of markups is as-designed because one would typically only select a markup if they wanted to move it around, scale it, etc. That's why in the current implementation, selecting a markup automatically enters its edit mode.
At the same time I understand your view where if I already activate a specific edit mode, it seems strange that that edit mode would change after simply selecting another markup.
Let me bring this up with the engineering team, and in the meantime, I'd suggest using the Autodesk.Viewing.Extensions.Markups.Core.EVENT_EDITMODE_CHANGED event to detect a change to the edit mode, and if needed, reset the mode to the one you want.

How to implement a threaded view?

I need to implement a threaded view of sorts in an old VB6 app. It should look similar to this:
So, it's like a TreeView of sorts but there are buttons on the right (for each row) that could be pressed. The view does not need to collapse - it always stays in the expanded mode. The users should be able to respond to each node (via the comment button on the far right). And, of course, users should be able to scroll through the entries.
What are some of the ways I could implement this? I am open to 3rd party controls, paid or not.
VSFlexGrid has an outline mode. You can set the indent per row via the RowOutlineLevel property. It supports word wrap, images, etc within its cells/columns so you should be able to get pretty close to what you want. It also supports owner-drawn which lets you fully customize the cell painting (for example, to get those rounded corners).
I'm sure there are other controls out there as well...

How to place a windowless control on top of a windows control?

Say, I have an Image control (which seems to be a window-less control) and I want to make sure that it is on top of a TextBox. No matter what I do, the Image control will not appear on top of the Text box.
Is there a way?
P.S. I know I can use a PictureBox, but it does not support transparency, thus I must have the Image control.
There is no way to place an image control over a normal textbox as they are drawn onto the form itself so will always be below any other windowed components.
If you have VB6 installation media there are drawn (windowless) versions of controls including a TextBox you can use that will (probably) do what you want; http://support.microsoft.com/kb/184687
A custom usercontrol of some kind if probably better .. what is it exactly you want to overlay the textbox with?
The Image Control is considered a graphical control, like shapes, so it is always inferior to text controls. If you really want a transparent image, you can use a Microsoft 2.0 Form instead(only if you have it). Images there can be on top of textboxes, and you can make it transparent by setting the Backstyle to Transparent(0).
Completely different approach to my other answer (hence the seperate Answer), but you can set AutRedraw and ClipControls on your Form to false and it will allow the Image control to render on the same layer as a windowed control. You can get some flakey redrawing in some cases but for a quick solution you could try it.
http://msdn.microsoft.com/en-us/library/aa733621(v=vs.60)
I've created a tranparent overlay control to add a kind of annotation layer on top of a VB6 app. I'll attempt to describe it from memory, and if that doesn't provide enough information then you can post back and I'll try to dig up the code.
First, add a new USerControl to you application. Give it a name like ImageEx, PictureEx, or TransparntImage. There are several properties that you will need to use. Ensure the control is Windowed, so it can sit on top of other windowed controls. Locate the MaskColor property and set it to Cyan (or whatever color you elect to use to indicate a tranparent area. There might be an addition property enable the masking behavior, just browse the properties. Set the control background color to that of the MaskColor. At this point you have an invisible control. In my control I painted on top of the surface for annotations, but you can PaintPicture or maybe even set the image property for a really simple approach.
Of course, to make this a re-usable control, you will want to code in your own properties that allow the MaskColor and image, etc to be set so that you can the drop one of these on any form you want.
Some links:
MaskColor Property
MackPicture Property
1) Remove all your textboxes , labels and ... (But memorize their name and location in the form)
2) Go to (project > components) and mark the (Microsoft Forms 2.0 Object Library) then click ok
3) Now you can see new controls under your default controls in your toolbox...
4) Use its textbox and label controls instead of the default controls
5) Right click on your Image Control then click (Bring To Front)

In Expression Blend for Windows Phone change image source of button in different states

In Expression Blend for Windows Phone, how can I change the image source of a button in different states. I want different images to be displayed in normal state and pressed state.
A couple of options come to mind, depending on what exactly you're trying to accomplish.
Once scenario is that you have a button that you want to act like a toggle, where you press it once and it stays pressed until you press it again, like a play button on a tape recorder (remember those?).
If that's what you're looking for, I would create a boolean property in your codebehind file, such as IsPlaying, that indicates whether your button is currently pressed or not.
Then you can create a ValueConverter that translates the true and false values to different images. Here's a write-up on creating a ValueConverter. The article talks about converting a bool to a Visibility, but the concept is the same.
In your BooleanToImage converter, or whatever you name it, you'll need to decide which image to show and load it up as a Bitmap. Then in your .xaml you'll bind to the IsPlaying property and set the converter to BooleanToImage. This approach works quite well for a lot of scenarios, and it's nice and tidy, as you don't have to think in terms of which image is playing; you can think about whether your app IsPlaying.
The other scenario is that you want to display the image briefly when the button is pressed, like an animation, then return to the previous state. In that case, your best bet is using the VisualStateManager, which allows you to define different appearances for your button in various states, such as Normal and Clicked. You can apply animations to transition between the states. Here's a walk-through that demonstrates using the VisualStateManager.

GTK - Don't highlight buttons on select / hover

I'm trying to write a kiosk GUI in ruby/gtk on ubuntu. I'm pretty fluent in ruby, but new to writing GUIs and not great with linux.
I'm using a touch screen, and am using our own images for buttons, e.g.
button_image = Gtk::Image.new(Gdk::Pixbuff.new "images/button_image.png")
#button = Gtk::Button.new
#button.add(button_image)
#button.set_relief(Gtk::RELIEF_NONE)
My issue is that when the buttons are pressed or remain selected (or hovered over, although this is less relevant with a touch screen), gtk shows fat, square borders around them. Obviously it's applying gtk's prelight / selected / active lighting to the buttons. I've tried changing the button properties in various ways, and also tryied hacking apart my theme, and while I can modify how the highlighting looks, I can't seem to completely get rid of it. Changing the color of the highlight via my theme is easy, but if I remove my setting there's still a default I can't get rid of.
Does anyone know if there's a way to stop it, or possibly make it transparent? Thanks in advance!
Sounds like you want to use exactly your image for the whole button, instead of putting an image inside the normal GtkButton - but still use all the normal behavior of the button.
The easiest way to do this is to just override the drawing. If you are on gtk2, connect to the "expose-event" signal, do your drawing there, and return true so that the default handler doesn't get run. If you are on gtk3, connect to the "draw" signal and do the same.
I tried meddling with the drawing as Federico suggested, but found that the most direct way to address this was instead to use an event box rather than a button. Event boxes accept clicks just like buttons, but don't respond to selecting, hovering, etc. In ruby, the code looks like this:
image = Gtk::Image.new("myfile.png")
event_box = Gtk::EventBox.new.add(image)
event_box.visible_window = false
event_box.signal_connect("button_press_event") do
puts "Clicked."
end
Most of this is exactly like a button; the *visible_window* method, obviously, keeps the event box from being visible under the button image.

Resources