让你的解决方案在一个vs里打开 然后把下面这个项目在一个新的vs里运行,要保证这个vs在你的解决方案的那个vs后面打开引用 EnvDTE; EnvDTE80;using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using EnvDTE; using EnvDTE80; using System.Runtime.InteropServices;namespace WindowsApplication120 { public partial class Form1 : Form { public Form1() { InitializeComponent(); DTE2 D = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE.8.0"); foreach (Project P in D.Solution.Projects) foreach (ProjectItem PI in P.ProjectItems) if (PI.Name.Contains(".cs")) { foreach (ProjectItem PI2 in PI.ProjectItems) if (PI2.Name.Contains(".Designer.cs")) { String FormName = PI2.Name.Substring(0, PI2.Name.Length - ".Designer.cs".Length); PI2.Document.ReplaceText("this.Text = \"" + FormName + "\";", "this.Text = \"" + FormName + "\";this.Font=new System.Drawing.Font(\"宋体\",20);", 0); break; } break; } } } }
foreach (DataRow DR in System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources().Rows) MessageBox.Show("实例名:"+DR["InstanceName"].ToString()+" 服务器名:"+DR["ServerName"].ToString());
wartim 1.这是什么 using EnvDTE; using EnvDTE80; 2.这个方法的你常用?可行性很高? this.text="..." 替换成 this.text="...";this.Font=new System.Drawing.Font("宋体",20);
第二个如果你的程序界面都是通过继承来的就比较好处理,否则你只能一个界面一个界面的修改了。一般修改了Form的字体大小后,里面的控件也会自动变化的。
有数据库的客户端当做Host,其他机器当做client
参照
2.可以用统一的资源文件,把可选的字体样式和大小写在Resources.resx里,所有winform加载的是Resources里的字体对象,这样可以做一个下拉列表让用户自己选择字体.再做个读写xml的功能,保存或读取已选字体
using System.Collections.Generic;
using System.Text;namespace WindowsApplication2
{
public class SqlLocator
{
[System.Runtime.InteropServices.DllImport("odbc32.dll")]
private static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);
[System.Runtime.InteropServices.DllImport("odbc32.dll")]
private static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);
[System.Runtime.InteropServices.DllImport("odbc32.dll")]
private static extern short SQLFreeHandle(short hType, IntPtr handle);
[System.Runtime.InteropServices.DllImport("odbc32.dll", CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
private static extern short SQLBrowseConnect(IntPtr hconn, System.Text.StringBuilder inString,
short inStringLength, System.Text.StringBuilder outString, short outStringLength,
out short outLengthNeeded);
private const short SQL_HANDLE_ENV = 1;
private const short SQL_HANDLE_DBC = 2;
private const int SQL_ATTR_ODBC_VERSION = 200;
private const int SQL_OV_ODBC3 = 3;
private const short SQL_SUCCESS = 0;
private const short SQL_NEED_DATA = 99;
private const short DEFAULT_RESULT_SIZE = 1024;
private const string SQL_DRIVER_STR = "DRIVER=SQL SERVER";
private SqlLocator() { }
//查找所有server
public static string[] GetServers()
{
string list = string.Empty;
IntPtr henv = IntPtr.Zero;
IntPtr hconn = IntPtr.Zero;
System.Text.StringBuilder inString = new System.Text.StringBuilder(SQL_DRIVER_STR);
System.Text.StringBuilder outString = new System.Text.StringBuilder(DEFAULT_RESULT_SIZE);
short inStringLength = (short)inString.Length;
short lenNeeded = 0;
try
{
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, henv, out henv))
{
if (SQL_SUCCESS == SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (IntPtr)SQL_OV_ODBC3, 0))
{
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, henv, out hconn))
{
if (SQL_NEED_DATA == SQLBrowseConnect(hconn, inString, inStringLength, outString,
DEFAULT_RESULT_SIZE, out lenNeeded))
{
if (DEFAULT_RESULT_SIZE < lenNeeded)
{
outString.Capacity = lenNeeded;
if (SQL_NEED_DATA != SQLBrowseConnect(hconn, inString, inStringLength, outString,
lenNeeded, out lenNeeded))
{
throw new ApplicationException("Unabled to aquire SQL Servers from ODBC driver.");
}
}
list = outString.ToString();
int start = list.IndexOf("{") + 1;
int len = list.IndexOf("}") - start;
if ((start > 0) && (len > 0))
{
list = list.Substring(start, len);
}
else
{
list = string.Empty;
}
}
}
}
}
}
catch
{
list = string.Empty;
}
finally
{
if (hconn != IntPtr.Zero)
{
SQLFreeHandle(SQL_HANDLE_DBC, hconn);
}
if (henv != IntPtr.Zero)
{
SQLFreeHandle(SQL_HANDLE_ENV, hconn);
}
}
string[] array = null;
if (list.Length > 0)
{
array = list.Split(',');
}
return array;
}
}
}
第一种方法如5楼说的,如果局域网中只有一个SQL服务,那么用这种方法是可以找到服务器
第二种就是先获取局域网IP集合,然后向指定的服务端口发送数据包,如果该IP返回指定的数据,则说明该机器是服务器,这个和6楼的方法类似
然后把下面这个项目在一个新的vs里运行,要保证这个vs在你的解决方案的那个vs后面打开引用
EnvDTE;
EnvDTE80;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using System.Runtime.InteropServices;namespace WindowsApplication120
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); DTE2 D = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE.8.0");
foreach (Project P in D.Solution.Projects)
foreach (ProjectItem PI in P.ProjectItems)
if (PI.Name.Contains(".cs"))
{
foreach (ProjectItem PI2 in PI.ProjectItems)
if (PI2.Name.Contains(".Designer.cs"))
{
String FormName = PI2.Name.Substring(0, PI2.Name.Length - ".Designer.cs".Length); PI2.Document.ReplaceText("this.Text = \"" + FormName + "\";",
"this.Text = \"" + FormName + "\";this.Font=new System.Drawing.Font(\"宋体\",20);", 0);
break;
}
break;
}
}
}
}
this.text="..." 替换成
this.text="...";this.Font=new System.Drawing.Font("宋体",20);
你在总数据库里保存客户端那台IP
其他客户端去获取这台机器IP即可
MessageBox.Show("实例名:"+DR["InstanceName"].ToString()+" 服务器名:"+DR["ServerName"].ToString());
1.这是什么
using EnvDTE;
using EnvDTE80;
2.这个方法的你常用?可行性很高?
this.text="..." 替换成
this.text="...";this.Font=new System.Drawing.Font("宋体",20);
实现的就是“在文件里替换”的功能,限制在解决方案里的form设计文件而已
就是把原来设计文件里所有this.Text="form1";替换成
this.Text="form1";this.Font=new System.Drawing.Font("宋体",20);而已,
等于全部form加了一句设置字体和大小的语句
其实你用vs自带的“在文件里替换”功能也一样
其实你每个form自己去设置一下字体也不会花很多时间