How to link a Bitmap to a button in C#? - c#

I'm a beginner programmer and I was wondering how I would go about linking an image to a button. Its for a childrens maths game which contains various questions like "how many sheep are there?", which would require them to select a button which has a certain value. Sorry if this is a really simple thing but I'm having some issues with it.
Thanks

Supposing you are doing a Windows Forms Application, you first place a button wherever you want, you can size it, put text on it... For what you want, those are the steps:
Select the button and find the Properties tab attached in the IDE.
In appearance, find the property "Text" and leave it blank, if there was any text.
In appearance section too, find BackgroundImage and click the button with "..." in the space.
When a window called "Select resource" appears, select "Local resource" and click "Import". When selected, click OK.
Now the image is binded to your Button background. Resize it as you want.
I hope this helps. There's not much info in the question.

Related

How can I find my controls on the form in Visual Studio (C#)

I have a form which I have created in Visual Studio and there are some controls on there with strange names which have events associated with them. I think the controls have been added in error. They are labels. I can't see them on the form, they must have no text or be behind something. How can I find them?
Use the View + (Other Windows) + Document Outline menu command. You'll get a tool window that displays all the children of the form. You can drag+drop a control up to its container to put it on top of the Z-order, in case such a label is covered by another control. Or right-click a rogue one and select Delete. Edit + Undo if you made a mistake.
Display the Properties window. (Use View, Properties Window if it is not already displayed.)
In the dropdown at the top of the Properties window, select the control that is giving you problems.
Change the Location to 0,0.
The control should now be at the top-left corner of your form, so that you can delete it.
If you can't see it, click in the white area outside of your form. Then the Format menu will appear from which you can pick Order, Bring to Front.
Copied from here

Create Simple Custom XAML / C# button

First of all, I'm new to XAML / C# (am iOS/Android programmer) so please bear with me instead of immediately voting down. My app has some GridViews that contain buttons. A lot of these buttons are similar and I would like to refactor this. For simplicity let's say my buttons are just Rectangles with a given color. This color might come from the Item class that defines the particular item in the GridView, or it might be hardcoded. I want the rectangle to change color on hover and pressed states. I want these colors to be parameters as well.
What is the best way to achieve this?
I tried to make a Button subclass but somehow I couldn't access the dependency properties in the VisualStateManager
I tried to write stuff in the code-behind but then I wasn't sure how to delegate the click command to the ViewModel class.
Could someone give me a small working example?
Thanks
You can do this with style templates.
In the Visual Studio designer, right-click on your button and then select Edit Template and then select Edit a Copy....
You will then be prompted to name your new style and also for which file to store it in. For now, just give it a unique name such as MyButtonStyle, and select the current file.
Visual Studio will then add a copy of the style to the current xaml document, and will update your button to use the new style.
<Button x:Name="Download" Style="{StaticResource MyButtonStyle}"></Button>
After this, you can update the new style including changing the colors for the different visual states such as hover or clicked.
You can then proceed to use the new style in other buttons in the same document. To use the style in multiple xaml documents, you have to pull it out into a common resource file.
So you want to adjust your button using custom properties. This is a good time to use a custom control. You can create whatever dependency properties you want and adjust your layout in your code. http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx

Create "dropdown" comment box within a GridView

I'm very new to ASP.NET and imagine this is possible, but I have a grid view with a handful of columns. One of the columns has a button, that when clicked, I'd like a box to appear below the button (to ensure its visibility) that allows the user to add comments, submit comments, and cancel. I'm not too worried about the last three pieces of functionality yet, but am stuck on just getting the comments box to pop up in the right spot.
My idea functionality would be to have the rows below the clicked button the shift down to leave a space for the comments box, and once it is submitted, to have it disappear and the other rows back in place. The second best solution would be to have a pop-up window.
I must also note that I am on a closed system that cannot have any plugins installed, though it does have jquery.
I can elaborate on my problem if needed.
you can use either Accordion, HoverMenu or ModalPopup. please go to the following link for the demo and select your choice.
AjaxControlToolkit Demo

How to create a menu similar to the Windows 7 Start Menu in WPF

I am contemplating having a menu in my WPF application that works in a similar way to the Windows 7 start menu.
In my mind, this means that I should make a user control that consitues a button. Clicking on the button will display a list box, and inside the list box it will be possible to search the items that are registered in the list box.
Would that be an advisable way of doing it or is it better to do something different such as changing the template of a menu control?
Thanks for any help, it is very much appreciated.
It seems you have the design already made up. Do exactly that! :) Create a button that when pressed, displays a panel that contains a list box and a text box. Tie an event to key presses in the text box that changes what the object bound to the list contains.
After that, it's just a SMOP!

trying to determine best user interface for layouts - winform button that shows dropdown

I am adding layout management to my winforms GUI which really just means that you can "Save" the current column settings with a "Key"
so for example you can have "View 1" or "View 2".
anyway, i dont have much real estate on the screen but i am trying to figure out the best way to:
Allow you to save the current layout as a "Saved Layout"
Allow you to select another layout and apply it.
Right now i have:
Save Icon
Combobox that has a list of saved layouts
Apply Icon
It works ok but it look a little unclear because the dropdown combobox is available and doesn't necessarly correspond to the view you are looking at.
I thought one idea was to instead of showing the combo, to just have two buttons:
Save layout
Apply existing layout.
when you clicked #2, this would then turn into a dropdown and show the other layouts.
thoughts or any other suggestions on a clear way to visualize this?
When space is tight, I'm a big fan of the LinkLabel and the ContextMenuStrip controls.
Save would pop up another form or something for entering the name of the current layout (or this could be set automatically), and Load displays the saved layouts in a popup menu that can then be clicked to select the desired layout.
LinkLabels take up less room than Buttons and ComboBoxes, and there's never any confusion about how they work.
I like your second idea, with one button to save and one generating a dropdown + apply
from my experience it's sometimes better to separate such logic into own modal window to select what to do and near your layout would be an icon suggesting for "advanced usage"
always try to "comment around" the components (use hints as much as possible) to tell the user what can be done with specific functionality
alt text http://www.talkingtext.com/wordpress_en/wp-content/uploads/2008/04/googleproduct.jpg
I try to keep the UI as uncluttered as I can, particularly when it comes to functionality that is of a more ancillary nature. To that end, if I can utilize something like a context menu that the user can right-click to pull up, I will. From the context menu, I generally provide a dialog box to support the functionality needed.
If the saving of the layout is a primary function of the form you are displaying to the user, it might warrant UI elements like a button or combo box that has dedicated real estate. Otherwise, I'd think seriously about putting the controls that provide that functionality on another pop-up dialog and using a mechanism like a context menu to bring up that dialog.
The downside to the context menu idea, initially, is that the user needs to "know" that the functionality exists. That might be solved by training or by tooltip hints or other means. Typically once the user "knows" that controls like ListViews, TreeViews and DataGridViews can have context menus, they don't have problems finding the functionality.
Just my two cents.

Categories