Click here to Skip to main content
15,608,936 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I a new to WPF but so far managed to create a status bar, but i want to create a grid with columns. I want to create this logic to it;

// Requirement that must implement.
0


I need some help, I have status bar but want to implement following logic.

a)Status bar must display information to the user such as; -Button to start and stop process(Started , Processed , Elapsed)

b) Start button must Repeat the below exactly every 500 ms c) Start button must als Serialize the object using a Json serializer

Send the json string using a TCP socket. d)Stop button must Pressing stop the echo process.


What I have tried:

// Front end XAML
Title="Simple Status Bar" Height="350" Width="525">  
    <Grid Background="BlanchedAlmond">  
        <TextBlock FontSize="50" Margin="200,-12,175,258" RenderTransformOrigin="1.443,0.195">Timer</TextBlock>  
        <TextBlock x:Name="clocktxtblock" FontSize="70" Margin="118,38,37,183"></TextBlock>  
        <Button x:Name="startbtn" Margin="38,137,350,126" Background="SkyBlue" Content="Start" FontSize="30" Click="startbtn_Click" ></Button>  
        <Button x:Name="stopbtn" Margin="200,137,190,126" Background="SkyBlue" Content="Stop" FontSize="30" Click="stopbtn_Click" ></Button>  
        <Button x:Name="resetbtn" Margin="360,137,28,126" Background="SkyBlue" Content="Reset" FontSize="30" Click="resetbtn_Click" ></Button>  
        <ListBox x:Name="elapsedtimeitem" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="433" Margin="56,199,0,0"/>



// WPF using C#
// WPF in C# code for XAML
    namespace StatusBar   
    {  
        public partial class MainWindow: Window   
        {  
            DispatcherTimer dt = new DispatcherTimer();  
            StatusBar  sw = new StatusBar ();  
            string currentTime = string.Empty;  
            public MainWindow()   
            {  
                InitializeComponent();  
                dt.Tick += new EventHandler(dt_Tick);  
                dt.Interval = new TimeSpan(0, 0, 0, 0, 1);  
            }  
      
            void dt_Tick(object sender, EventArgs e)   
            {  
                if (sw.IsRunning)   
                {  
                    TimeSpan ts = sw.Elapsed;  
                    currentTime = String.Format("{0:00}:{1:00}:{2:00}",  
                    ts.Minutes, ts.Seconds, ts.Milliseconds / 10);  
                    clocktxtblock.Text = currentTime;  
                }  
            }  
      
            private void startbtn_Click(object sender, RoutedEventArgs e)  
            {  
                sw.Start();  
                dt.Start();  
            }  
      
            private void stopbtn_Click(object sender, RoutedEventArgs e)   
            {  
                if (sw.IsRunning)  
                {  
                    sw.Stop();  
                }  
                elapsedtimeitem.Items.Add(currentTime);  
            }  
      
            private void resetbtn_Click(object sender, RoutedEventArgs e)   
            {  
                sw.Reset();  
                clocktxtblock.Text = "00:00:00";  
            }  
        }  
    } 
Posted
Updated 7-Sep-22 9:01am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900