您好我不熟悉使用USB连接控制硬件.我有一个Arduino UNO微控制器,正在寻找资源让我入门.我在C#(Visual Studio 2010)中编程,并想知道是否有一些我可以用来设置/测试我的连接的基础知识.我正在寻找像WinForm中的复选框一样简单的东西,在Arduino上切换高低之间的数字I/O引脚.一开始就找不到多少.
提前致谢.
我有一个程序在Windows资源管理器中打开一个文件夹,它传递了一个目录路径:
procedure TfrmAbout.ShowFolder(strFolder: string);
begin
ShellExecute(Application.Handle,PChar('explore'),PChar(strFolder),nil,nil,SW_SHOWNORMAL);
end;
Run Code Online (Sandbox Code Playgroud)
有没有办法传递这个文件名(完整的文件名路径或只是名称+扩展名),并在Windows资源管理器中打开文件夹,但也要突出显示/选择?我要去的位置有很多文件,然后我需要在Windows中操作该文件.
我已经构建了一个递归函数来获取文件夹路径的目录大小.它的工作原理,但随着我必须搜索的目录数量不断增加(以及每个相应文件夹中的文件数量),这是一种非常缓慢,低效的方法.
static string GetDirectorySize(string parentDir)
{
long totalFileSize = 0;
string[] dirFiles = Directory.GetFiles(parentDir, "*.*",
System.IO.SearchOption.AllDirectories);
foreach (string fileName in dirFiles)
{
// Use FileInfo to get length of each file.
FileInfo info = new FileInfo(fileName);
totalFileSize = totalFileSize + info.Length;
}
return String.Format(new FileSizeFormatProvider(), "{0:fs}", totalFileSize);
}
Run Code Online (Sandbox Code Playgroud)
这是在所有子目录中搜索参数路径,因此dirFiles数组变得非常大.有没有更好的方法来实现这一目标?我已经四处寻找,但还没有找到任何东西.
我想到的另一个想法是将结果放入缓存中,当再次调用该函数时,尝试查找差异并仅重新搜索已更改的文件夹.不确定这是不是一件好事......
您好我想知道是否可以从我的WinForms应用程序向Outlook 2010发送搜索查询.也就是说,不是搜索.PST文件,因为我一直在搜索并发现,我正在尝试在Outlook中显示结果列表,就像我自己在搜索框中输入一样.
如果可能,任何示例代码都会有所帮助.此外,是否可以直接在所有邮件项目中执行搜索,通常在您进行搜索时,它会梳理当前文件夹.谢谢.
我试图使用按钮事件从我的SQL Server数据库表中删除一整行.到目前为止,我的尝试都没有成功.这就是我想要做的:
public static void deleteRow(string table, string columnName, string IDNumber)
{
try
{
using (SqlConnection con = new SqlConnection(Global.connectionString))
{
con.Open();
using (SqlCommand command = new SqlCommand("DELETE FROM " + table + " WHERE " + columnName + " = " + IDNumber, con))
{
command.ExecuteNonQuery();
}
con.Close();
}
}
catch (SystemException ex)
{
MessageBox.Show(string.Format("An error occurred: {0}", ex.Message));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我一直收到错误:
System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的第一次机会异常发生错误:操作数类型冲突:文本与int不兼容
表中的所有列都是TEXT类型.为什么我不能将类型的函数参数string与列进行比较以找到匹配?(然后删除该行?)
您好我有一个带有"收藏夹"菜单的ToolStripMenu,我想在运行时在WinForms应用程序中添加子项.我有一个datagridview,我右键单击以显示具有"添加到收藏夹"选项的上下文菜单.当该事件被触发时,我想使用datagriview中的所选行中的一些文本添加一个项目(我知道该怎么做)到这个收藏夹菜单.棘手的部分是我需要为我的newlyCreatedToolStripMenuItem_Click事件创建代码.我将在稍后确定如何保存我的收藏夹列表.
所以我们要去:
右键单击datagridview"约翰史密斯"行
从中选择"添加到收藏夹" ContextMenu
收藏夹ToolStripMenu中添加了一个新项目,内容为"John Smith"
单击"John Smith" ToopStripMenuItem会触发一个动作(例如在daragridview行中选择该行等)
有什么好的开始想法?
我正在效仿这个例子:http: //lawrencebarsanti.wordpress.com/2009/12/16/display-error-messages-with-tballoonhint/
我正在尝试仅在编辑框中的当前值不可接受时显示气球提示.检查是在触发时触发的OnExit.仍应允许显示气球,直到确定该值为止.我还尝试在用户离开编辑时以编程方式显示气球以显示初始错误.
代码有效,但不是第一次.我必须使用无效值离开一次,更改为可接受的值,然后再次使用无效值.我想这是因为我在尝试显示气球之前无法启用或禁用ShowHint属性.
这是我的代码:
procedure TForm1.Edit1Exit(Sender: TObject);
var
R: TRect;
Bad : Boolean;
begin
//Check if edit has only numbers
if StrIsReal(Edit1.Text) then
begin
if(StrToFloat(Edit1.Text) >= 0.5) then
begin
//Value is ok
SpeedButton1.Visible := false;
Edit1.ShowHint := false;
BalloonHint1.HideHint;
Edit1.Text := FloatToStrF(StrToFloat(Edit1.Text), ffFixed, 8, 2);
end
else
begin
//Is decimal, but not at least 0.5
Bad := true;
end;
end
else
begin
Bad := true;
end;
if Bad then
begin
//Invalid number
Edit1.ShowHint …Run Code Online (Sandbox Code Playgroud) 您好我正在尝试通过我正在构建的C#WinForm为我的SQL编写一些值.我收到一个我无法解决的错误.
我这叫:
SQL.insertIntoChildTable(Convert.ToInt32(child_IDTextBox.Text),
child_FirstNameTextBox.Text,
child_LastNameTextBox.Text,
Convert.ToInt32(parent1IDTextBox.Text),
Convert.ToInt32(parent2IDTextBox.Text),
birthdayDateTimePicker.Value.ToShortDateString(),
age.ToString(),
null, null, null, null, null,
child_disciplineTextBox.Text, child_NotesTextBox.Text);
Run Code Online (Sandbox Code Playgroud)
由此:
public static void insertIntoChildTable(int childID, string firstName, string lastName, int parent1ID, int parent2ID, string birthdate, string age, string lastCheckedInTime, string lastCheckedInBy, string lastCheckOutTime, string lastCheckedOutBy, string ageGroup, string disciplineNotes, string otherNotes)
{
try
{
using (SqlConnection connection = new SqlConnection(Global.connectionString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO ProjectList (ChildID, FirstName, LastName, Parent1ID, Parent2ID, Birthdate, Age, LastCheckedInTime, LastCheckedInBy, LastCheckOutTime, LastCheckedOutBy, AgeGroup, …Run Code Online (Sandbox Code Playgroud) 您好我正在尝试将Excel文件转换为我的dataGridView,并且它有列名称问题,因为Excel文件的格式化方式,文档的其余部分有两个设置单元格.但是,列名实际上在第2行.如何跳过文件读取的第一行,以便dataGridView中的列显示第二行的单元格值?
当前代码:
var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Extended Properties=Excel 8.0;", openFileDialog1.FileName);
string query = String.Format("select * from [{0}$]", "Sheet1");
var adapter = new OleDbDataAdapter(query, connectionString);
DataSet ds = new DataSet();
adapter.Fill(ds);
DataTable dt = ds.Tables[0];
techGrid.DataSource = dt;
Run Code Online (Sandbox Code Playgroud) 我使用以下代码从DataGridView读取电子邮件地址,然后创建Outlook电子邮件.除了将新电子邮件设置为topMost和/或打开为对话框窗口之外,这非常有效,这意味着在新电子邮件窗口打开时我无法在Outlook中单击或执行任何其他操作.如果我打开新电子邮件并尝试在收件箱中搜索或查找某些内容,则会出现问题.在我关闭或发送电子邮件之前,我的申请也不会回复(被锁定).
有没有办法创建一个新的电子邮件,仍然允许常规功能?如果我从Outlook本身单击新的电子邮件按钮,我可以根据需要打开这些按钮,使用搜索等.
该this.TopMost = false行是隐藏我的WinForms应用程序并在前面显示新的电子邮件窗口.
try
{
string emailString = resultsGrid[resultsGrid.Columns["Email"].Index, resultsGrid.SelectedCells[resultsGrid.Columns["Email"].Index].RowIndex].Value.ToString();
if(emailString.Contains("mailto:"))
{
emailString = emailString.Replace("mailto:", "");
}
this.TopMost = false;
// Create the Outlook application by using inline initialization.
Outlook.Application oApp = new Outlook.Application();
//Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.Subject = "";
oMsg.To = emailString;
oMsg.Body = "";
oMsg.Display(true);
oMsg = null;
oApp = null;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("An error occurred: {0}", ex.Message));
}
Run Code Online (Sandbox Code Playgroud)
同样奇怪的是,如果我在电子邮件中写一些东西并关闭它,我可以保存它.如果我这样做,当我打开电子邮件备份时,它会返回到锁定状态.我开始认为这与电子邮件的创建方式有关,因此一些设置或属性正在应用并随之保存.
c# ×8
delphi ×2
outlook ×2
search ×2
arduino ×1
datagridview ×1
delete-row ×1
directory ×1
excel ×1
explorer ×1
hint ×1
recursion ×1
sql ×1
sql-server ×1
topmost ×1