Total members 11890 |It is currently Thu Apr 18, 2024 10:50 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






 Project Name:   A tool to change the default source control client
 Programmer:   Baloghp
 Type:   Application
 Technology:  C#
 IDE:   NONE
 Description:   I just wanted to use two different source control providers on the same machine. I installed both clients but I discovered that the later installed is always the default. I searched the net all over for a tool, but no usable application was found.

sample code :
csharp code
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FileTypeAndIcon
{
public partial class IconForm : Form
{
#region PROPERTIES

/// <summary>
/// Used for containing file types and thier icons information.
/// </summary>
private Hashtable icons;

/// <summary>
/// USed for getting registered file types and their icons information.
/// </summary>
private RegisteredFileType fileType;

#endregion

#region CONSTRUCTORS

public IconForm()
{
InitializeComponent();
this.fileType = new RegisteredFileType();
}

#endregion

#region GUI EVENTS

private void IconForm_Load(object sender, EventArgs e)
{
try
{
//Gets file type and icon info.
this.icons = this.fileType.GetFileTypeAndIcon();

//Loads file types to ListBox.
foreach (object objString in this.icons.Keys)
{
this.lbxFileType.Items.Add(objString);
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}

private void btnSearch_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtSearch.Text.Trim()))
return;
string searchName = "";
if (!this.txtSearch.Text.Contains("."))
searchName = "." + this.txtSearch.Text; //Add a dot if the search text does not have it.
else
searchName = this.txtSearch.Text;

//Searches in the collections of file types and icons.
object objName = this.icons[searchName];
if (objName != null)
{
this.lbxFileType.SelectedItem = searchName;
}
}

private void lbxFileType_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (this.lbxFileType.Items.Count <= 0 || this.lbxFileType.SelectedItem == null)
return;
string fileType = this.lbxFileType.SelectedItem.ToString();
this.showIcon(fileType);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}

private void txtSearch_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtSearch.Text.Trim()))
{
this.btnSearch.Enabled = false;
}
else
{
this.btnSearch.Enabled = true;
}
}

/// <summary>
/// Shows the icon associates with a specific file type.
/// </summary>
/// <param name="fileType">The type of file (or file extension).</param>
private void showIcon(string fileType)
{
try
{
string fileAndParam = (this.icons[fileType]).ToString();
if (String.IsNullOrEmpty(fileAndParam))
return;

//Use to store the file contains icon.
string fileName = "";

//The index of the icon in the file.
int iconIndex = 0;
string iconIndexString = "";

int index = fileAndParam.IndexOf(",");
//if fileAndParam is some thing likes that: "C:\\Program Files\\NetMeeting\\conf.exe,1".
if (index > 0)
{
fileName = fileAndParam.Substring(0, index);
iconIndexString = fileAndParam.Substring(index + 1);
}
else
fileName = fileAndParam;

if (!string.IsNullOrEmpty(iconIndexString))
{
//Get the index of icon.
iconIndex = int.Parse(iconIndexString);
if (iconIndex < 0)
iconIndex = 0; //To avoid the invalid index.
}

//Gets the handle of the icon.
IntPtr lIcon = RegisteredFileType.ExtractIcon(this.Handle.ToInt32(), fileName, iconIndex);

//The handle cannot be zero.
if (lIcon != IntPtr.Zero)
{
//Gets the real icon.
Icon icon = Icon.FromHandle(lIcon);

//Draw the icon to the picture box.
this.pbIconView.Image = icon.ToBitmap();
}
else //if the icon is invalid, show an error image.
this.pbIconView.Image = this.pbIconView.ErrorImage;
}
catch (Exception exc)
{
throw exc;
}
}

#endregion
}
}

Attachment:
SCCswitch.gif
SCCswitch.gif [ 4.52 KiB | Viewed 4577 times ]





Attachments:
SCCswitch.zip [4.27 KiB]
Downloaded 774 times
SCCswitch_src.zip [8.21 KiB]
Downloaded 803 times

_________________
Please recommend my post if you found it helpful. ,
java,j2ee,ccna ,ccnp certified .
Author:
Expert
User avatar Posts: 838
Have thanks: 2 time

updated.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : A tool to change the default source control client
 Change the default underline style of link     -  
 How to change the default order on forums from ascending to     -  
 Change letters to upper case by default     -  
 Help on Urchin tool ?     -  
 using pen tool in photoshop     -  
 Globus tool kit     -  
 client server client     -  
 How to work with PowerDesigner tool to design ERD model?     -  
 Use the 'default' case     -  
 String type default value     -  



Topic Tags

C# Projects







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com