Results 1 to 13 of 13

Thread: button text

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    London United Kingdom
    Posts
    334

    Angry button text

    I am working on WPF program and I have a button which display 2 lines of text. What I need help on is, I want the top line of the text to have bigger font than the bottom text but how. I would be grateful if anyone can help. thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: button text

    that's a WPF question, which should be asked in the WPF forum. i'll notify a moderator

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: button text

    The thing that comes to my mind is the FlowDocument. You could do something like this:

    Code:
            <Button Name="Button1">
                <FlowDocument>
                    <Paragraph>
                        <Span FontSize="20">Hello</Span>
                        <LineBreak></LineBreak>
                        <Span FontSize="10">World</Span>
                    </Paragraph>
                </FlowDocument>
            </Button>
    Last edited by dday9; Jan 30th, 2014 at 06:04 PM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    London United Kingdom
    Posts
    334

    Re: button text

    Quote Originally Posted by dday9 View Post
    The thing that comes to my mind is the FlowDocument. You could do something like this:

    Code:
            <Button Name="Button1">
                <FlowDocument>
                    <Paragraph>
                        <Span FontSize="20">Hello</Span>
                        <LineBreak></LineBreak>
                        <Span FontSize="10">World</Span>
                    </Paragraph>
                </FlowDocument>
            </Button>
    Thanks dday's. Is it possible to do it in code because the data will be pull from sqlserver. Thanks

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: button text

    Quote Originally Posted by wiadus View Post
    Thanks dday's. Is it possible to do it in code because the data will be pull from sqlserver. Thanks
    I don't understand, this is the XAML code.
    Last edited by dday9; Jan 31st, 2014 at 11:44 AM. Reason: Extensible Application Markup Language, Not Extensible Markup Language
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: button text

    I think what the OP is asking for is that the text will be coming from a database... so the XAML should only need a placeholder, and then through the vb code, replaced with the value retrieved from the database. So the button would be templated in the XAML, with the actual text inserted later.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: button text

    Thread moved to the WPF forum.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    London United Kingdom
    Posts
    334

    Re: button text

    Sorry dday's what I meant was code in vb as the text will come from database. Thanks

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: button text

    Then you would do what TG suggested in post #6. I'm not good with WPF but I think that you could do something like this:
    Code:
    <Paragraph>
        <Span FontSize="20" Name="Line1" />
        <LineBreak></LineBreak>
        <Span FontSize="10" Name="Line2" />
    </Paragraph>
    But I wouldn't know how to set the text of those spans. That would be left to some WPF experts.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: button text

    You could put two TextBlock inside the Button and give them different names
    Code:
    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Button Content="Button" Height="44" HorizontalAlignment="Left" Margin="316,125,0,0" Name="button1" VerticalAlignment="Top" Width="114" Click="button1_Click" />
            <Button Height="69" HorizontalAlignment="Left" Margin="94,76,0,0" Name="button2" VerticalAlignment="Top" Width="112" >
                <StackPanel>
                    <TextBlock Name="Label1" FontSize="20" Text="test"></TextBlock>
                    <TextBlock Name="Label2" FontSize="12" Text="test"></TextBlock>
                </StackPanel>
            </Button>
        </Grid>
    </Window>
    And set the Text like

    Code:
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        Label2.Text = "Dee-u";
        Label1.Text = "Experiment";
    }
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    London United Kingdom
    Posts
    334

    Re: button text

    thanks it work perfect

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: button text

    Quote Originally Posted by techgnome View Post
    I think what the OP is asking for is that the text will be coming from a database... so the XAML should only need a placeholder, and then through the vb code, replaced with the value retrieved from the database. So the button would be templated in the XAML, with the actual text inserted later.

    -tg
    It can easily be done by binding button to property or method in the view model. Sorry I don't have tool make quick sample so here is a link (one of many):

    http://stackoverflow.com/questions/3...button-content

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width