Search Results

Search found 17464 results on 699 pages for 'radio button'.

Page 5/699 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to fix the position of the button in applet

    - by user1609804
    I'm trying to make an applet that has a buttons in the right, where each button is corresponding to a certain pokemon. I already did it, but the buttons isn't fixed.they keep following the mouse. please help. This is my code: import javax.swing.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import java.applet.*; import java.awt.event.*; import java.awt.*; public class choosePokemon extends Applet implements ActionListener { private int countPokemon; private int[] storePokemon; private int x,y; //this will be the x and y coordinate of the button BufferedImage Picture; public int getCountPokemon(){ //for other class that needs how many pokemon return countPokemon; } public int[] getStoredPokemon(){ //for other class that needs the pokemon return storePokemon; } public void init(){ x=0;y=0; try{ Picture = ImageIO.read(new File("pokeball.png")); } catch( IOException ex ){ } } public void paint( Graphics g ){ pokemon display = new pokemon(); // to access the pokemon attributes in class pokemon ButtonGroup group = new ButtonGroup(); //create a button group for( int a=0;a<16;a++ ){ // for loop in displaying the buttons of every pokemon(one pokemon, one button) display.choose( a ); //calls the method choose in which accepts an integer from 0-15 and saves the attributes of the pokemon corresponding to the integer JButton pokemonButton = new JButton( display.getName() ); // creates the button pokemonButton.setActionCommand( display.getName() ); // isasave sa actioncommand yung name ng kung ano mang pokemon pokemonButton.addActionListener(this); //isasama yung bagong gawang button sa listener para malaman kung na-click yung button pokemonButton.setBounds( x,y,50,23 ); group.add( pokemonButton ); //eto naman yung mag-aadd sa bagong gawang button sa isang group na puro buttons(button ng mga pokemon) y+=23; if( a==7 ){ x+=50; y=0; } add( pokemonButton ); //will add the button to the applet } g.drawImage( Picture, 120, 20, null ); } public void actionPerformed(ActionEvent e) { try{ //displays the picture of the selected pokemon Picture = ImageIO.read(new File( "pokemon/" + e.getActionCommand() + ".png" )); } catch( IOException ex ){ } } public boolean chosen( int PChoice ){ //this will check if the chosen pokemon is already the player's pokemon boolean flag = false; for( int x=0; x<countPokemon && !flag ;x++ ){ if( storePokemon[x]==PChoice ){ flag = true; } } return flag; }

    Read the article

  • change the value of the button of the button clicked

    - by user269431
    On inserting the new <li>, I have to set the value of the button clicked to Delete. How can I do that? With the actual code, it`s working only once, and on adding other list, the button no more has the the value 'Delete'. $("#mylist :button").click( function() { var text = $(this).val(); if (text == "Delete") { $(this).parent().remove(); } else { $(this).val("Delete"); } }); $("#mylist li:last-child").live('click', function() { $(this).parent().append('<li>' + '<input type = "textbox">' + '<input type = "button" value= "Save">' + '</li>'); }); <div> <ul id="mylist"> <li id="1">1<button id="Button3">Delete</button> </li> <li id="2">2<button id="Button2">Delete</button></li> <li id="3">3<button id="another_entry">Save</button></li> </ul>

    Read the article

  • SWT: problems with clicking button after using setEnabled() on Linux

    - by Laimoncijus
    Hi, I have a strange case with SWT and Button after using setEnabled() - seems if I disable and enable button at least once - I cannot properly click with mouse on it anymore... Already minify code to very basic: import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class TestButton { public TestButton() { Display display = new Display(); Shell shell = new Shell(display); GridLayout mainLayout = new GridLayout(); shell.setLayout(mainLayout); shell.setSize(100, 100); Button testButton = new Button(shell, SWT.PUSH); testButton.addSelectionListener(new TestClickListener()); testButton.setText("Click me!"); //testButton.setEnabled(false); //testButton.setEnabled(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } class TestClickListener implements SelectionListener { @Override public void widgetDefaultSelected(SelectionEvent e) { } @Override public void widgetSelected(SelectionEvent e) { System.out.println("Click!"); } } public static void main(String[] args) { new TestButton(); } } When I keep these 2 lines commented out - I can properly click on a button and always get "Click!" logged, but if I uncomment them - then I can't click on button properly with mouse anymore - button visually seems to be clicked, but nothing is logged... Am I doing something wrong here? Or maybe it's some kind of bug on Linux platform? Because on Mac running the same code I never experienced such problems... Thanks for any hint! P.S. Running code on Ubuntu 9.10, Gnome + Compiz, Sun Java 1.6.0.16

    Read the article

  • jQuery - Increase the value of a counter when a button is clicked

    - by Taimur
    Hi, I'm making a system where a user clicks a button and their score increases. There is a counter which I would like to increase the value of using jQuery (so that the page does not need to refresh) when the button is clicked. How would I go about this? <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script> <script type="text/javascript"> $("#update").click(function() { $("#counter")++; } </script> #update is the button, #counter is the counter. In php, ++ increases something's value. What's the jQuery equivalent? Also, when the button is clicked, it needs to send a request which updates the score value in a mysql database as well, without the page refreshing. Does anyone know how I would do that? Thanks a lot UPDATE: I've tried a few of the methods below, but nothing seems to work! Do I need to change anything else for it to work? I've created a test page for it: <html> <body> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script> <script type="text/javascript"> var count = 0; $("#update").click(function() { count++; $("#counter").html("My current count is: "+count); } </script> <button id="update" type="button">Button</button> <div id="counter">1</div> </body> </htlm>

    Read the article

  • IE 7 does not like jquery('<button/>').attr('type','button')

    - by salmane
    I am trying to create a button using jquery. I use the following code jquery('<button/>', {type:'button'}).text(name) However this works in Safari , FF IE8 but not IE7 i tried to use the attr function : jquery('<button/>').attr('type','button').text(name) this does not work either. any ideas what would work? I suppose if I don't assign a type it would default to button but i rather do that thanks for your help

    Read the article

  • Dell Synaptics touch pad's middle mouse button gets mapped as normal click

    - by Henrik
    How do I make the middle touch pad's button work? xinput --test 11 yields button press 1 button press 1 For pressing both the left and the middle button. I have tried to do xinput set-button-map 11 1 4 2 and so on, but as the --test shows that button 1 is being depressed, then probably the issue is at a lower level than with X11's perception of what mouse buttons I'm pressing (or assigning button-map 11 1 2 3 and clicking the right button in firefox, wouldn't trigger the middle-click on the link)

    Read the article

  • Dell Synaptics touchpad's middle mouse button gets mapped as normal click

    - by Henrik
    How do I make the middle touchpad's button work? xinput --test 11 yields button press 1 button press 1 For pressing both the left and the middle button. I have tried to do xinput set-button-map 11 1 4 2 and so on, but as the --test shows that button 1 is being depressed, then probably the issue is at a lower level than with X11's perception of what mouse buttons I'm pressing (or assigning button-map 11 1 2 3 and clicking the right button in firefox, wouldn't trigger the middle-click on the link)

    Read the article

  • Is it possible to make the Numpad 5 button work as the Numpad Down button while Num Lock is on?

    - by Eddy
    I hope someone can help me out with this; I use a laptop and I like to play games a lot that are arrow key dependent. So after a while of using my laptop, I accidentally broke the Down Arrow key. So I decided to try and find out how to make the Numpad5 button work as the Numpad Down button while Numlock is on. I was trying to use AutoHotkey, but so far I've had no luck. Can anyone help me out with this? So far the scripts I used that didn't work were Numpad5::NumpadDown or Numpad5::Down. Am I doing something wrong here?

    Read the article

  • Javascript Back Button - Stop back from closing window

    - by Evan
    How do I get the "back" button seen in my demo to NOT close the browser window? If this can't be prevented, then at least provide them with a confirmation box alerting them the window is trying to close and ask them if they want to continue. I'm using a javascript back button link and forward button link to control the user's history inside a modal/lightbox window. Here's a demo of what is happening... When you begin, the second page will have a link to the modal window, so click that, then click the "back" button in the window as it will take you BACK to the start page. That's the issue I'm having as I don't want this to happen. http://www.apus.edu/_test/evan/modal/start.htm <a href="javascript:history.go(-1)">Back Button</a> <a href="javascript:history.go(1)">Foward Button</a>

    Read the article

  • LinearLayout of a WebView and a Button.

    - by Timmmm
    Hi, I recently struggled with an apparently simple Android layout: I wanted a WebView above a Button. It worked fine with the following parameters: WebView: Height: wrap-content Weight: unset (by the way, what is the default?) Button: Height: wrap-content Weight: unset However if the web page became too big it spilled out over the button. I tried various combinations of weights and heights, and all except one either completely hide the button, or partially cover it. This is the one that works (copied from http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/res/layout/main.xml): WebView: Height: 0 Weight: 1 Button: Height: wrap-content Weight: unset If you change any of those, e.g. give button a weight or change the WebView height to wrap-content then it doesn't work. My question is: Why? Can someone please explain what on Earth the android layout system is thinking?

    Read the article

  • Changing Image In a Button After Being Clicked?

    - by BuZzZzJaY
    Creating a game in Android using multiple Buttons to display an image from the drawable folder. I want to change the button to a different image after the button has been clicked on. Here is the button code: <Button android:id="@+id/b36" android:background="@drawable/black" android:layout_width="45px" android:layout_height="45px" /> I can't find anything about how to change the actual image of the button. You can change the color of the button by using the following code in the java file: b36.setBackgroundColor(0xAA00AA00);

    Read the article

  • MVVM Group Radio Button

    - by LnDCobra
    What is the best way of binding a number of RadioButtons to an enum using MVVM? The only way I can think of is binding each group box's IsChecked to a property, and in the setter of that property assign a value to an enum in the view model. Any help is appreciated.

    Read the article

  • Android: scaling a button with a background image.

    - by jkhouw1
    I'm probably just being daft but my Google searches are not working out well. I have a bunch of buttons i add in code that all have dynamic text. I've set a background image for each of these buttons since the default greybutton doesn't work well for my application. This works perfectly and when the text size (or content) changes, the button automatically grows to accommodate the expanded text. What doesn't work is that I'd like the button to scale proportionally - i.e. if the background image is round, i'd like it to stay round rather than oval as the button gets bigger. With an imagebutton, there is a property "Adjust view bounds" that does exactly this but I cant put text on an imagebutton. Is there something equivalent for a regular button? or am I going about this wrong? i also tried setting the width of the button in code, but I can't seem to determine the new height (button.getHeight() returns 0)

    Read the article

  • Stop IE6 overwriting Button text when setting value.

    - by RoToRa
    I've got a button which contains a span I need for styling: <button id="example" name="example" value="Example"><span>Example</span></button> IE6 has a bug that it submits the contents of the button instead of it's value, but I've already worked around that. Now I need to change the value of the button and the text in the span in JavaScript/jQuery: jQuery("#example").val("Changed").children("span").text("Changed"); However IE6 also changes the contents of the button when setting the value per JavaScript/jQuery, so that the span is lost. Does any one know of a way other that identifying IE6 with jQuery.browser that I could use to avoid that?

    Read the article

  • Why this button doesn't cause triple postback?

    - by focus
    We have developed a page with a asp.net and debugging it accidentally we have discovered on our page button with the next code on onclik attribute onclick="__doPostBack('ctl00$FormPlace$m_userTaskMarkAsUnreadButton',''); __doPostBack('ctl00$FormPlace$m_userTaskMarkAsUnreadButton','');WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$FormPlace$m_userTaskMarkAsUnreadButton", "", true, "", "", false, false))" It seems that the button do three postbacks but when we click it only cause on postback. With this code seems that de button will cause three postbacks!! We have try it with Internet Explorer and Firefox and the button only cause on postback always. Are browsers who avoid that the button do three postback ? Or Is Asp.net server who avoid the three postback? We don't understand why the button behaves correctly if onclick attribute has three call to do Postbacks. Thanks

    Read the article

  • Button INPUT that save datas and link at the same time

    - by user1722384
    Im doing a questionare (form) and i need to put a button submit that do two things : 1) Be a button type INPUT ( because I need to use this kind of button on my php code, I've if(@$_POST['Next']) for save the dates of the form in my DB). 2) That this button will have a link for go to the next screen of the questionare. I tried with a href="demo2.html" target="_blank"><input class="buttonNext" name="submit" type="submit" value="NEXT &#8592" ></a This code don't works but with IE browser on the page page appears a circle next to my button that are the link. So the button don't works, only save the data, but don't link to the next page. How can I solve it ?

    Read the article

  • how to bind data binding source to group radio buttons

    Hi I am working on windows c# application (visual studio 20008).In my form I have 5 Radio buttons ,grouped by group box. I have to bind this radio button to data binding source. this.rdoptPlus.DataBindings.Add(new Binding("Checked", MemberDefinitionsBindingSource, "UnaryOperator", true)); this.rdoptMinus.DataBindings.Add(new Binding("Checked", MemberDefinitionsBindingSource, "UnaryOperator", true)); i am unable to bind single datacolum to 5 radio buttons,please help me  read moreBy masuri suhasiniDid you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • Picking up radio station when connecting monitor on latop

    - by Goddard
    I have a laptop Asus G73JW ROG-A3B7M Intel Core i7 || 16GB RAM || 802.11n+BT || 2 x 500GB Hybrid Drives || Nvidia GTX 460M and I am picking up some staticy radio station when connecting my monitor over RGB connector. My radio system is connected via my laptops headphone jack. If I disconnect my extra monitor the radio station static disappears. I am not sure what this is related to or even how to debug such an issue. Any help is appreciated. The monitor is a Acer P216HL and the stero is a TeAC nxt

    Read the article

  • WPF ICommand over a button

    - by toni
    Hi, I have implemented a custom IComand class for one of my buttons. The button is placed in a page 'MyPage.xaml' but its custom ICommand class is placed in another class, not in the MyPage code behind. Then from XAML I want to bind the button with its custom command class and then I do: MyPage.xaml: <Page ...> <Page.CommandBindings> <CommandBinding Command="RemoveAllCommand" CanExecute="CanExecute" Executed="Execute" /> </Page.CommandBindings> <Page.InputBindings> <MouseBinding Command="RemoveAllCommand" MouseAction="LeftClick" /> </Page.InputBindings> <...> <Button x:Name="MyButton" Command="RemoveAllCommand" .../> <...> </Page> and the custom command button class: // Here I derive from MyPage class because I want to access some objects from // Execute method public class RemoveAllCommand : MyPage, ICommand { public void Execute(Object parameter) { <...> } public bool CanExecute(Object parameter) { <...> } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } } My problem is how to say MyPage.xaml that Execute and CanExecute methods for the button is in another class and not the code behind where is placed the button. How to say these methods are in RemoveAllCommand Class in XAML page. Also I want to fire this command when click mouse event is produced in the button so I do an input binding, is it correct? Thanks

    Read the article

  • WPF ICommand over a button

    - by toni
    I have implemented a custom IComand class for one of my buttons. The button is placed in a page 'MyPage.xaml' but its custom ICommand class is placed in another class, not in the MyPage code behind. Then from XAML I want to bind the button with its custom command class and then I do: MyPage.xaml: <Page ...> <Page.CommandBindings> <CommandBinding Command="RemoveAllCommand" CanExecute="CanExecute" Executed="Execute" /> </Page.CommandBindings> <Page.InputBindings> <MouseBinding Command="RemoveAllCommand" MouseAction="LeftClick" /> </Page.InputBindings> <...> <Button x:Name="MyButton" Command="RemoveAllCommand" .../> <...> </Page> and the custom command button class: // Here I derive from MyPage class because I want to access some objects from // Execute method public class RemoveAllCommand : MyPage, ICommand { public void Execute(Object parameter) { <...> } public bool CanExecute(Object parameter) { <...> } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } } My problem is how to say MyPage.xaml that Execute and CanExecute methods for the button is in another class and not the code behind where is placed the button. How to say these methods are in RemoveAllCommand Class in XAML page. Also I want to fire this command when click mouse event is produced in the button so I do an input binding, is it correct? Thanks

    Read the article

  • JQuery: Toggle submit button according to if terms are agreed with or not

    - by Svish
    I have a checkbox with id terms and a submit button in my form with class registration. I would like the submit button to be disabled initially, and then to be toggled on and off whenever the user toggle on and off the terms checkbox. I would also like to have a confirmation dialog pop up when the submit button is clicked and that if it is confirmed the submit button will be disabled again (to prevent duplicate clicking). I have gotten the last part and the first part working (I think), but I can't figure out how to get the toggling working. This is what I have so far: $(document).ready(function() { // Disable submit button initially $('form.registration input[type=submit]').attr('disabled', 'disabled'); // Toggle submit button whenever the terms are accepted or rejected $('#terms').change(function() { if($('#terms:checked').val() !== null) $('input[type=submit]', this).attr('disabled', ''); else $('input[type=submit]', this).attr('disabled', 'disabled'); }); // Ask for confirmation on submit and disable submit button if ok $('form.registration').submit(function() { if(confirm('Have you looked over your registration? Is everything correct?')) { $('input[type=submit]', this).attr('disabled', 'disabled'); return true; } return false; }); }); Could someone help me make this work? I'm a total JQuery newb at the moment, so any simplifications and fixes are welcome as well.

    Read the article

  • HOW CAn I Differciate the button click Event

    - by SHASHANK
    hello All i have a problem. i m making Some wpf button Dynamic through C#.i m using it A loop for this now i m trying to find all button Click Event. i find it But It Work Same on All The button Click how Can i Differciate all the button . thanks in Advance shashank `for (int i = 0; i < 2; i++) { Button b1 = new Button(); //this.RegisterName("myAnimatedBrush", b1); b1.Name = "button" + i; b1.Height = 200; b1.Width = 200; b1.Margin = new Thickness(0, -100, 0, 0); b1.HorizontalAlignment = HorizontalAlignment.Left; b1.Content = "English"; b1.Background = System.Windows.Media.Brushes.Pink; b1.Click+=new RoutedEventHandler(b1_Click); canvasbtn.Children.Add(b1); Canvas.SetLeft(b1,b1.Width * i); }`

    Read the article

  • Scale transform in xaml (in a controltemplate) on a button to perform a "zoom"

    - by Matt B
    Hi all, I've got a button with an image in it and it's being styled by the following: <ControlTemplate x:Key="IconButton" TargetType="Button"> <Border> <ContentPresenter Height="80" Width="80" /> </Border> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard TargetProperty="Opacity"> <DoubleAnimation From="1" To="0.5" Duration="0:0:0.5" /> <DoubleAnimation From="0.5" To="1" Duration="0:0:0.5" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <BeginStoryboard> <Storyboard TargetProperty="Width"> <DoubleAnimation From="80" To="95" Duration="0:0:0.2" /> </Storyboard> </BeginStoryboard> </EventTrigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Cursor" Value="Hand"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> Button is as follows: <Button Template="{StaticResource IconButton}" Name="btnExit"> <Image Source="Images/Exit.png" /> </Button> The problem is that the width doesn't change when my mouse goes over. (Or at least - the width of the image does not...) I believe there is a "scale" transform I can use to enlarge the button and all it's contents? how would I do that here...? Thanks.

    Read the article

  • A WPF Image Button

    - by psheriff
    Instead of a normal button with words, sometimes you want a button that is just graphical. Yes, you can put an Image control in the Content of a normal Button control, but you still have the button outline, and trying to change the style can be rather difficult. Instead I like creating a user control that simulates a button, but just accepts an image. Figure 1 shows an example of three of these custom user controls to represent minimize, maximize and close buttons for a borderless window. Notice the highlighted image button has a gray rectangle around it. You will learn how to highlight using the VisualStateManager in this blog post.Figure 1: Creating a custom user control for things like image buttons gives you complete control over the look and feel.I would suggest you read my previous blog post on creating a custom Button user control as that is a good primer for what I am going to expand upon in this blog post. You can find this blog post at http://weblogs.asp.net/psheriff/archive/2012/08/10/create-your-own-wpf-button-user-controls.aspx.The User ControlThe XAML for this image button user control contains just a few controls, plus a Visual State Manager. The basic outline of the user control is shown below:<Border Grid.Row="0"        Name="borMain"        Style="{StaticResource pdsaButtonImageBorderStyle}"        MouseEnter="borMain_MouseEnter"        MouseLeave="borMain_MouseLeave"        MouseLeftButtonDown="borMain_MouseLeftButtonDown">  <VisualStateManager.VisualStateGroups>  ... MORE XAML HERE ...  </VisualStateManager.VisualStateGroups>  <Image Style="{StaticResource pdsaButtonImageImageStyle}"         Visibility="{Binding Path=Visibility}"         Source="{Binding Path=ImageUri}"         ToolTip="{Binding Path=ToolTip}" /></Border>There is a Border control named borMain and a single Image control in this user control. That is all that is needed to display the buttons shown in Figure 1. The definition for this user control is in a DLL named PDSA.WPF. The Style definitions for both the Border and the Image controls are contained in a resource dictionary names PDSAButtonStyles.xaml. Using a resource dictionary allows you to create a few different resource dictionaries, each with a different theme for the buttons.The Visual State ManagerTo display the highlight around the button as your mouse moves over the control, you will need to add a Visual State Manager group. Two different states are needed; MouseEnter and MouseLeave. In the MouseEnter you create a ColorAnimation to modify the BorderBrush color of the Border control. You specify the color to animate as “DarkGray”. You set the duration to less than a second. The TargetName of this storyboard is the name of the Border control “borMain” and since we are specifying a single color, you need to set the TargetProperty to “BorderBrush.Color”. You do not need any storyboard for the MouseLeave state. Leaving this VisualState empty tells the Visual State Manager to put everything back the way it was before the MouseEnter event.<VisualStateManager.VisualStateGroups>  <VisualStateGroup Name="MouseStates">    <VisualState Name="MouseEnter">      <Storyboard>        <ColorAnimation             To="DarkGray"            Duration="0:0:00.1"            Storyboard.TargetName="borMain"            Storyboard.TargetProperty="BorderBrush.Color" />      </Storyboard>    </VisualState>    <VisualState Name="MouseLeave" />  </VisualStateGroup></VisualStateManager.VisualStateGroups>Writing the Mouse EventsTo trigger the Visual State Manager to run its storyboard in response to the specified event, you need to respond to the MouseEnter event on the Border control. In the code behind for this event call the GoToElementState() method of the VisualStateManager class exposed by the user control. To this method you will pass in the target element (“borMain”) and the state (“MouseEnter”). The VisualStateManager will then run the storyboard contained within the defined state in the XAML.private void borMain_MouseEnter(object sender,  MouseEventArgs e){  VisualStateManager.GoToElementState(borMain,    "MouseEnter", true);}You also need to respond to the MouseLeave event. In this event you call the VisualStateManager as well, but specify “MouseLeave” as the state to go to.private void borMain_MouseLeave(object sender, MouseEventArgs e){  VisualStateManager.GoToElementState(borMain,     "MouseLeave", true);}The Resource DictionaryBelow is the definition of the PDSAButtonStyles.xaml resource dictionary file contained in the PDSA.WPF DLL. This dictionary can be used as the default look and feel for any image button control you add to a window. <ResourceDictionary  ... >  <!-- ************************* -->  <!-- ** Image Button Styles ** -->  <!-- ************************* -->  <!-- Image/Text Button Border -->  <Style TargetType="Border"         x:Key="pdsaButtonImageBorderStyle">    <Setter Property="Margin"            Value="4" />    <Setter Property="Padding"            Value="2" />    <Setter Property="BorderBrush"            Value="Transparent" />    <Setter Property="BorderThickness"            Value="1" />    <Setter Property="VerticalAlignment"            Value="Top" />    <Setter Property="HorizontalAlignment"            Value="Left" />    <Setter Property="Background"            Value="Transparent" />  </Style>  <!-- Image Button -->  <Style TargetType="Image"         x:Key="pdsaButtonImageImageStyle">    <Setter Property="Width"            Value="40" />    <Setter Property="Margin"            Value="6" />    <Setter Property="VerticalAlignment"            Value="Top" />    <Setter Property="HorizontalAlignment"            Value="Left" />  </Style></ResourceDictionary>Using the Button ControlOnce you make a reference to the PDSA.WPF DLL from your WPF application you will see the “PDSAucButtonImage” control appear in your Toolbox. Drag and drop the button onto a Window or User Control in your application. I have not referenced the PDSAButtonStyles.xaml file within the control itself so you do need to add a reference to this resource dictionary somewhere in your application such as in the App.xaml.<Application.Resources>  <ResourceDictionary>    <ResourceDictionary.MergedDictionaries>      <ResourceDictionary         Source="/PDSA.WPF;component/PDSAButtonStyles.xaml" />    </ResourceDictionary.MergedDictionaries>  </ResourceDictionary></Application.Resources>This will give your buttons a default look and feel unless you override that dictionary on a specific Window or User Control or on an individual button. After you have given a global style to your application and you drag your image button onto a window, the following will appear in your XAML window.<my:PDSAucButtonImage ... />There will be some other attributes set on the above XAML, but you simply need to set the x:Name, the ToolTip and ImageUri properties. You will also want to respond to the Click event procedure in order to associate an action with clicking on this button. In the sample code you download for this blog post you will find the declaration of the Minimize button to be the following:<my:PDSAucButtonImage       x:Name="btnMinimize"       Click="btnMinimize_Click"       ToolTip="Minimize Application"       ImageUri="/PDSA.WPF;component/Images/Minus.png" />The ImageUri property is a dependency property in the PDSAucButtonImage user control. The x:Name and the ToolTip we get for free. You have to create the Click event procedure yourself. This is also created in the PDSAucButtonImage user control as follows:private void borMain_MouseLeftButtonDown(object sender,  MouseButtonEventArgs e){  RaiseClick(e);}public delegate void ClickEventHandler(object sender,  RoutedEventArgs e);public event ClickEventHandler Click;protected void RaiseClick(RoutedEventArgs e){  if (null != Click)    Click(this, e);}Since a Border control does not have a Click event you will create one by using the MouseLeftButtonDown on the border to fire an event you create called “Click”.SummaryCreating your own image button control can be done in a variety of ways. In this blog post I showed you how to create a custom user control and simulate a button using a Border and Image control. With just a little bit of code to respond to the MouseLeftButtonDown event on the border you can raise your own Click event. Dependency properties, such as ImageUri, allow you to set attributes on your custom user control. Feel free to expand on this button by adding additional dependency properties, change the resource dictionary, and even the animation to make this button look and act like you want.NOTE: You can download the sample code for this article by visiting my website at http://www.pdsa.com/downloads. Select “Tips & Tricks”, then select “A WPF Image  Button” from the drop down list.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >