Showing posts with label Visual Studio 2008. Show all posts
Showing posts with label Visual Studio 2008. Show all posts

Sunday, January 31, 2010

Custom GroupBox Control for Silverlight 3

In previous post i put xaml that allow to create GroupBox using XAML.

Here i am adding custom groupbox control.

image

Download link :   GroupBox control for Silverlight 3

Codeplex Link :  Silverlight3 GroupBox

Sunday, June 14, 2009

Remove Focus Rectangle From Button

Article is about to remove focus rectangle or say cues from Button in window form application.

First let discuss what default focus rectangle. Please look at following image , in that image OK button has default focus so it display cues rectangle.

image 
(FlatStyle == System)

When we want to set background image of button to make button attractive in that case this default rectangle create problem with look and feel.

image
(FlatStyle = Standard)
 
 image
(FlatStyle = Flat)

In above two image need to set FlatApperance.BorderStyle =0. You can visualize that in all above case default focus rectangle make button look ugly with background image.

To remove this cues ( Default focus rectangle ) you need to set ShowFocusCues property of Button to false but this property does not directly available to Button. This property available in ButtonBase class with protected access specifier. In order to set this property to false we need to create class that inherits from Button or ButtonBase and set this property explicitly false.

class CustomButton : System.Windows.Forms.Button
    {
        protected override bool ShowFocusCues
        {
            get
            {
                return false;
            }
        }
}

image
Now see that default focus rectangle is removed.

More generic class for Button.

class CustomButton : System.Windows.Forms.Button
   {
       private bool _DisplayFocusCues = true;
       protected override bool ShowFocusCues
       {
           get
           {
               return _DisplayFocusCues;
           }
       }

       public bool DisplayFocusCues
       {
           get
           {
               return _DisplayFocusCues;
           }
           set
           {
               _DisplayFocusCues = value;
           }
       }
   }

Using this class you can set DisplayFocusCues at design time so CustomButton work with any case. ( Want to display focus rectangle or not).

image 

Hope this solution is help you to create button without cues.

Your suggestion is always invited.

Saturday, June 13, 2009

Passing Parameter to InstallUtil

When installing window service or any installer ( class inherits from install class) required custom parameter at run time , Need to pass as parameter of installutil.

Crating window service using article (http://dotnetstep.blogspot.com/2009/06/install-windowservice-using-installutil.html).  This article suggest you add installer ( ProjectInstaller). Now we use installer class events to configure ServiceProcessInstaller and ServiceInstaller as per parameter pass to installutil.

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
           this.BeforeInstall += new InstallEventHandler(ProjectInstaller_BeforeInstall);
            this.BeforeUninstall += new InstallEventHandler(ProjectInstaller_BeforeUninstall);
        }       

        void ProjectInstaller_BeforeInstall(object sender, InstallEventArgs e)
        {
            // Configure Account for Service Process.
            switch(this.Context.Parameters["Account"])
            {
                case "LocalService":
                    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;
                    break;
                case "LocalSystem":
                    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
                    break;
                case "NetworkService":
                    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.NetworkService;
                    break;
                case "User":
                    this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
                    this.serviceProcessInstaller1.Username = this.Context.Parameters["UserName"];
                    this.serviceProcessInstaller1.Password = this.Context.Parameters["Password"];
                    break;
            }      
            // Configure ServiceName
            if(!String.IsNullOrEmpty(this.Context.Parameters["ServiceName"]))
            {               
                this.serviceInstaller1.ServiceName = this.Context.Parameters["ServiceName"];
            }
        }

        void ProjectInstaller_BeforeUninstall(object sender, InstallEventArgs e)
        {
            if (!String.IsNullOrEmpty(this.Context.Parameters["ServiceName"]))
            {
                this.serviceInstaller1.ServiceName = this.Context.Parameters["ServiceName"];
            }
        }
    }

Above ProjectInstaller class handle two events : BeforeInstall and BeforeUninstall. BeforeInstall is called just before install method of installer (ProjectInstaller) called via InstallUtil and same way BeforeUninstall called just before Uninstall method of projectinstaller class. After adding that two event handler use following to configure service using installutil.

1. Install
installutil /Account=User /UserName=admin /Password=admin /ServiceName=WinService1 /i WindowService1.exe

2. Uninstall
installutil /ServiceName=WinService1 /u WindowService1.exe

This will also help you configure WindowService1.exe with two different name and different account.
installutil /Account=User /UserName=admin /Password=admin        /ServiceName=WinService1 /i WindowService1.exe

installutil /Account=LocalSystem /ServiceName=WinService2 /i WindowService1.exe

Install window service without using installutil

Article is about to install window service without using InstallUtil utility.
Windows XP or Later has command line utility called sc . (This utility talks with service controller and with services from command line).
SC is a window base utility. AS explain in article http://dotnetstep.blogspot.com/2009/06/install-windowservice-using-installutil.html sc does not required ProjectInstaller.

1. Start service using sc
          sc start ServiceName

2. Stop serivce
         sc stop ServiceName

3. Delete window service
        sc delete servicename
        Note : During delete call if service is in running state then service is delete when nexttime service is stop or PC restart.

4. Create window service
       sc create ServiceName binpath= “c:\windowservice1\windowservice1.exe”

       Apart from above many option available . For that just go to command prompt and type sc create /?

  For example configure service running account.

sc create servicename binpath= “c:\windowservice1\windowservice1.exe” obj= administrator password= pass

Hope this article will help you .

Please give your comment or idea about this.

In above all case Service ServiceName ( Mark as blue) , don’t use display name.

 image

Install WindowService using installutil.

This article is about to install to window service using installutil.exe. InstallUtil.exe or simply say installutil utility comes up with .NET Framework 2.0.

Steps.
1. Create new Window Service Project.
image 
2. After that open services1.cs in design mode . It looks like this.
image 
3. Now right click on design window. It open popup menu with installer option.
image
4. When you click on Add Installer. It will will add new class called projectinstaller.cs. It contain serviceprocessinstaller1 and serviceinstaller component. ServiceProcess installer is used to configure service account and serviceinstaller contain information about service.
image
5. Apart from above ProjectInstaller.cs contain following code which is used to call from installutil.
image
In above code RunInstaller attribute marked as true. So InstallUtil take this thing into consideration and use this information to call installer.

To install using installutil open VS 2005/VS 2008 command prompt or go to  %windir%\Microsoft.NET\Framework\v2.0.50727.

installutil.exe /i  WindowService1.exe ( To Install ).

installutil.exe /u WindowSerivce1.exe ( To uninstall).

Installutil use Installer class (Projectinstaller) to install service.

If you mark RunInstlaller as false then this installutil not work.

If you don’t want to use installutil to install wndow service then go to http://dotnetstep.blogspot.com/2009/06/install-window-service-without-using.html.

Sunday, June 7, 2009

Redirect console application output to another application in .NET

In .NET sometime it is required to execute system command and capture its result or data in application that execute that command.
For example you want to execute ipconfig command from .NET application and display its result in window application or need to read output of .NET console application.

For this purpose you need to use Process class that belongs to System.Diagnostics namespace.

//Create process class object
System.Diagnostics.Process p = new System.Diagnostics.Process();

// Set StartInfo property.
// Set redirection true for Error and output stream.
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;

// When you set redirection you must set UseShellExecute to false .
p.StartInfo.UseShellExecute = false;

// Set window style
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

// Set Command paramter.
p.StartInfo.FileName = "ipconfig";
p.StartInfo.Arguments = " /all";

// Set CreateNoWindow to true as window is not required here.
p.StartInfo.CreateNoWindow = true;

// Following two events are new in .NET framework 2.0 which allow us to capture data asynchronously.

p.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_ErrorDataReceived);

// Start the process.
p.Start();

// Must call following two methods in order to capture data asynchronously.
p.BeginErrorReadLine();
p.BeginOutputReadLine();

// Wait for Process to Exit ( This is not must done ).
p.WaitForExit();

// Event Handler for ErrorStream.
void p_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
            System.Diagnostics.Debug.WriteLine(e.Data);   
}

// Event Handler for OutputStream.
void p_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
           System.Diagnostics.Debug.WriteLine(e.Data);
}

Even you can use this functionality to make utility like process command background and produce result in window application.

p.StartInfo.FileName = @"%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe";
p.StartInfo.Arguments = @" -v / -f -p C:\Blog\WebSite1 c:\WebSite1Compile";
// Note : Replace %windir% with your window directory. or use p.StartInfo.EnvironmentVariables["windir"]

Above is the one example to compile website application from window application.

Apart from this there is event called Exited associated with Process class object. In order to receive this event you need to set EnableRasingEvents property to true value.

Give your comment and idea on this article.

Saturday, June 6, 2009

Usage of aspnet_compiler.exe and aspnet_merge.exe

Whenever asp.net website or webapplication publish,aspnet_compiler.exe is used for compilation. 

Example :

WebSite : c:\myProject\TestSite

1 . Go to Visual Studio Tool from program menu and start Visual studio command prompt.
                                     or
     If you do not have visual studio installed on your machine and just .NET Framework 2.0 installed on your machine then also you can use aspnet_compiler tool. 
- Start > run  and type cmd.
- set path=%windir%\Microsoft.NET\Framework\v2.0.50727
- aspnet_compiler –v / –p c:\myproject\testsite c:\testcompile
  
   It will compile c:\myproject\testsite and put published site in c:\testcompile. 
- When you compile site using above command site is not updatable after publish. 
-  If you want to site updatable after publish add –u option to it.
- It is good to add –f option in order to override existing published site.
- Fore more help just type aspnet_compiler /?

Now let discuss about aspnet_merge.exe tool. This tool is introduce later and it is used to merge all assemblies that is located in bin directory of published site. When you published website project many assemblies are in bin directories depending upon your option.

- In aspnet_compiler if you add –fixednames option then it will generate single assembles for each page otherwise it is generated per directory (this is default for asp.net website project).

- Main disadvantage of different assembles either way is problem with reflection. You are not able to get control and page information located in another assemblies without assemblies loading programmatically.

- aspnet_merge.exe tool merge all aspnet generated assemblies to single assemblies.

Example :

1. set path=%programfiles%\Microsoft SDKs\Windows\v6.0A\bin
2. aspnet_merge c:\testcompile
   This will create single DLL ( assembly ) in bin directory.
3. To set generated assembly name use this.
    aspnet_merge –o Single.dll c:\testcompile.

Hope this will help you.

Please give your comment and advice on this.

Thursday, April 9, 2009

CrystalReport redistribution package

This is just a small information about Crystal Report redistribution package. You can fine different packages related to Visual Studio at following location

“<system drive>:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages”

At this location you can different directories that contains .exe or .msi related to Visual Studio 2008 installation.

Friday, April 3, 2009

WSE 3.0 Setting Tool For Visual Studio 2008

WSE 3.0 Setting Tool not available in VS 2008. Here i am explaining steps required to enable it in Visual Studio 2008.

1 . Download Following Tool
     WSE 3.0 Tools
2.  Install that MSI File.
     “Basically that installation is for Visual Studio 2005.”
3.  After installation you find one file at following location.
     C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins
      Here i assumed that your OS is installed at C:\.
4. At that location you find this file “WSESettingsVS3.Addin”.
5. Open file in Notepad , you find following XML content.   

  <HostApplication>
    <Name>Microsoft Visual Studio Macros</Name>
    <Version>8.0</Version>
  </HostApplication>
  <HostApplication>
    <Name>Microsoft Visual Studio</Name>
    <Version>8.0</Version>
  </HostApplication>

change it to

  <HostApplication>
    <Name>Microsoft Visual Studio Macros</Name>
    <Version>9.0</Version>
  </HostApplication>
  <HostApplication>
    <Name>Microsoft Visual Studio</Name>
    <Version>9.0</Version>
  </HostApplication>

save that file.
6. Open Visual Studio , Tools – > Options –> Environments

image

Add Following
“C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins”

(Note : In Image it displayed D:\ as my os is on D Drive.)

7. Close all instance of Visual Studio.

8. Open it again , create web service application . Now you can se that WSE 3.0 Setting option enable.