重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Function ReadFile(ByRef a As String) As String
振安ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
a = "bian"
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As String = "yuanlai"
ReadFile(a)
''想要的结果就是在这里使用a的值是"bian"
MsgBox(a)
End Sub
===================
以上就可以,不知道你“ByRef a As b”的b是什么东西
只需要用变量存储 Image 对象,然后不需要的时候释放掉就行了。
Dim img1 As Image
img1 = Image.FromFile(pic)
PictureBox1.Image = img1
'窗口关闭时
img1 = Nothing
如满意,请采纳。
读文件内容到TextBox :
Try
Using sr As StreamReader = New StreamReader("C:\\TestFile.txt")
textbox1.Text = sr.ReadToEnd()
End Using
Catch E As Exception
Console.WriteLine(E.Message)
End Try
修改完成后,保存到文件:
Using sw As StreamWriter = New StreamWriter("C:\\TestFile.txt")
sw.Write(textbox1.Text)
sw.Close()
End Using
其中,流构造的参数
New StreamReader("C:\\TestFile.txt")
New StreamWriter("C:\\TestFile.txt")
中的"C:\\TestFile.txt"可以用OpenFileDialog和SaveFileDialog的FileName属性替换.
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
Using sr As StreamReader = New StreamReader(openFileDialog1.FileName)
textbox1.Text = sr.ReadToEnd()
End Using
Catch E As Exception
Console.WriteLine(E.Message)
End Try
End If
保存的时候换成SaveFileDialog就好
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using _5dRss.Const;
using _5dRss.lib.Data.Tool;
public partial class admin_admin_dbmanage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//生成备份文件列表
ListBackupFiles();
if (!Page.IsPostBack)
{
Showmsg.Visible = false;
//数据库路径
lilDBPath.Text = HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"];
//新建一个 FileInfo 对象,并获得数据库文件的大小,然后转换单位为KB
FileInfo myFileInfo = new FileInfo(lilDBPath.Text);
lilDBSize.Text = Convert.ToString(myFileInfo.Length/1024) + " KB";
//如果两个参数都不为空,则继续执行
if (Request.QueryString["cmd"] != null Request.QueryString["source"] != null)
{
//备份数据库原文件名
string sourceFileName = Request.QueryString["source"];
//如果 cmd 参数为 DelFile
if (Request.QueryString["cmd"].Equals("DelFile"))
{
//删除备份数据库文件
File.Delete(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\" + sourceFileName);
//刷新备份文件列表
ListBackupFiles();
Showmsg.Visible = true;
Showmsg.Text = "div align='center' style='margin-bottom:8px;'img src='images/aL.gif' style='margin-bottom:-6px;'/span class='alertTxt'删除备份数据库成功!/spanimg src='images/aR.gif' style='margin-bottom:-6px;'//div";
}
//如果 cmd 参数为 Restore
if (Request.QueryString["cmd"].Equals("Restore"))
{
//用备份文件覆盖原文件
File.Copy(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\" + sourceFileName, HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"], true);
//刷新备份文件列表
ListBackupFiles();
Showmsg.Visible = true;
Showmsg.Text = "div align='center' style='margin-bottom:8px;'img src='images/aL.gif' style='margin-bottom:-6px;'/span class='alertTxt'还原备份数据库成功!/spanimg src='images/aR.gif' style='margin-bottom:-6px;'//div";
}
}
}
}
protected void lnkbtnCompactDB_Click(object sender, EventArgs e)
{
//压缩修复数据库
AccessDBtool.CompactAccessDB(SysConfig.ConnectionString, HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"]);
Showmsg.Visible = true;
Showmsg.Text = "div align='center' style='margin-bottom:8px;'img src='images/aL.gif' style='margin-bottom:-6px;'/span class='alertTxt'压缩修复数据库成功!/spanimg src='images/aR.gif' style='margin-bottom:-6px;'//div";
}
protected void lnkbtnBackupDB_Click(object sender, EventArgs e)
{
string sourceFileName = HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"];
string destFileName = HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\" + "Backup_";
destFileName += DateTime.Now.ToString("yyyyMMddHHmmss");
destFileName += ".mbk";
//将数据库文件Copy到Backup目录,如果有重名文件就覆盖原文件
File.Copy(sourceFileName, destFileName, true);
//生成备份文件列表
ListBackupFiles();
Showmsg.Visible = true;
Showmsg.Text = "div align='center' style='margin-bottom:8px;'img src='images/aL.gif' style='margin-bottom:-6px;'/span class='alertTxt'备份数据库成功!/spanimg src='images/aR.gif' style='margin-bottom:-6px;'//div";
}
/// summary
/// 生成备份文件列表
/// /summary
/// returns文件列表,文件详细信息及操作选项的HTML代码/returns
public void ListBackupFiles()
{
//如果目录不存在则创建次目录
if (!Directory.Exists(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\"))
Directory.CreateDirectory(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\");
DirectoryInfo mydir = new DirectoryInfo(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\");
StringBuilder sb = new StringBuilder();
foreach (FileInfo f in mydir.GetFiles())
{
sb.Append("a href='backup/" + f.Name + "' target='_blank'img border='0' src='images/mdb.gif' style='margin:4px 3px -3px 0px'/" + f.Name + "/a a href='?cmd=DelFilesource=" + f.Name + "' title='删除备份文件'删除/a | a href='?cmd=Restoresource=" + f.Name + "' title='删除备份文件'还原数据库/a | " + f.Length/1024 + " KB | " + f.CreationTime + "br /");
}
lilBackupFileList.Text = sb.ToString();
}
}
把下面这句换成你的数据库地址:
//数据库路径
// lilDBPath.Text = HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"];
1、首先引用命名空间:using Microsoft.Win32;
2、几个基本主键:
Registry.ClassesRoot;对应于HKEY_CLASSES_ROOT主键
Registry.CurrentUser; 对应于HKEY_CURRENT_USER主键
Registry.LocalMachine; 对应于 HKEY_LOCAL_MACHINE主键
Registry.User; 对应于 HKEY_USER主键
Registry.CurrentConfig; 对应于HEKY_CURRENT_CONFIG主键
Registry.DynDa; 对应于HKEY_DYN_DATA主键
Registry.PerformanceData; 对应于HKEY_PERFORMANCE_DATA主键
3、返回或创建一个注册表键
Dim Key1 As Microsoft.Win32.RegistryKey
Key1 = My.Computer.Registry.CurrentUser '返回当前用户键
Dim Key2 As Microsoft.Win32.RegistryKey
Key2 = Key1.OpenSubKey("northsnow") '返回当前用户键下的northsnow键
If Key2 Is Nothing Then
Key2 = Key1.CreateSubKey("northsnow") '如果键不存在就创建它
End If
不知道你想实现什么功能。
如果你的意思是使用某种WINDOW API相对应的功能。需要查看MSDN中
.NETFRAMEWORK是否有相关的类库与函数。
VB中Declare 用于在模块级别中声明对动态链接库 (DLL) 中外部过程的引用。
可以引用windows api的函数。
但是如果你需要寻找一些你需要的类似WINDOWSAPI功能的函数。例如:FindWindow. 有一些函数功能类似。
例如 :Process currentProcess = Process.GetCurrentProcess();
IntPtr hWndToProcess = currentProcess .MainWindowHandle;
获得程序进程的窗口。
但是要是获得桌面窗口这个就要用到api了。