derinpdavis.webs.com

Paint Brush Application Using HTML5 Canvas

 

Best way of making a software application is to "develop a web-based application and host it on Cloud", then we don't have to worry about installations, as it will be easily updatable and easy to manage versions. Also our application can support different platforms like Windows, Linux, iOS, Android, etc... Only thing you have to test it with different browsers.

Please visit the link below to get started with a Paintbrush Application using HTML5 Canvas.

http://www.codeproject.com/Articles/427422/Paint-Brush-Application-Using-HTML5-Canvas

Style button with image, in WPF

The first thing is, we have to make a custom Button control

*Note : Your application can be named "ImageButtonSample"

//file::ImageButton.cs

namespace ImageButtonSample
{
    public class ImageButton : Button
    {
        private ImageSource _myImage;

        public ImageSource MyImage
        {
            get { return _myImage; }
            set { _myImage = value; }
        }
    }
}

Next we have to define the style for this button.

//file::ImageButton.xaml

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ImageButtonSample">
    <!--  A button style that displays an attached image -->
    <Style TargetType="{x:Type local:ImageButton}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid>
                        <Image
                            Source="{Binding Path=(local:ImageButton.MyImage),
                            RelativeSource={RelativeSource FindAncestor,
                            AncestorType={x:Type Button}}}"
                            HorizontalAlignment="Left" Margin="8,0,0,0"                             
                            Height="16" Width="16" />
                        <TextBlock
                            Text="{TemplateBinding Content}"
                            HorizontalAlignment="Center" />
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

The new stylish image button is ready. Now we can use it in our application.

*Note : Don't forget to add the resource dictionary reference in your client application

 <Window x:Class="ImageButtonSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ImageButtonSample"        
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <ResourceDictionary Source="ImageButton.xaml"/>
    </Window.Resources>
    <Grid>
        <local:ImageButton MyImage="apply.png"
                           Content="Apply" Margin="89,116,63,116" />
    </Grid>
</Window>

Serial Port Communication

System.IO.Ports - namespace contains a class named "SerialPort".

This class facilitate us to do the communication with serial [COM] ports.

How to open a serial port ?

SerialPort serialPort = new SerialPort(); 

//configuring the serial port
serialPort .PortName = "COM1";
serialPort .BaudRate = 9600;
serialPort .DataBits = 8;
serialPort .Parity = Parity.None;
serialPort .StopBits = StopBits.One;

//opening the serial port
serialPort .Open();

Open() function calling is actually opening the COM port. So this call can be inside a try catch block to capture the errors while opening.

 How to send data  to serial port?

There are two functions for this purpose.

1.  serialPort.Write();  //receives text or byte[] with offset and count

2. serialPort.WriteLine() //receives text 

 How to read data from serial port?

Handle the DataReceived event of SerialPort class.

serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived); 

void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
     string data = serialPort.ReadExisting();
}

 To test the serial port communication applications, we can use the "Virtual Serial Port Emulator" if you does'nt have the actual communication device.

Read password in Console Application

I had a situation to read a password using console application. System.Console doesn't allow to read a password as like in winforms. So we have to manipulate the same in Console.

        public static string ReadPassword()
        {
            string password = "";
            ConsoleKeyInfo info;

            do
            {
                info = Console.ReadKey(true); //Read key without echo

                if (info.Key == ConsoleKey.Backspace)
                {
                    if (!string.IsNullOrEmpty(password))
                    {
                        password = password.Substring(0, password.Length - 1);
                    }
                    //Print backspace, clear the character by overwrite, again backspace
                    Console.Write("\b" + " " + "\b");
                }
                else
                {
                    password += info.KeyChar;
                    Console.Write("*");
                }
            }
            while (info.Key != ConsoleKey.Enter);
            
            Console.Write(Environment.NewLine);

            return password;
        }

Then you can use this function

string _password = ReadPassword();

Malayalam Shows Australia

Malayalam Shows Australia

www.malayalamshows.com.au

new and exclusive site for Malayalam Shows in Australia

IT IN AUSTRALIA

ITINA SERVICES

Web Developement, Software Development, Animation, Desing, Mobile Apps, Consulting.

based on Melbourne, VIC, Australia

www.itinaservices.com

Recent Forum Posts

No recent posts