我有一个TextBox
和一个标签.单击按钮后,我执行以下代码:
label1.Content = textbox1.Text;
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何启用标签的文本换行?可能有太多文本要显示在一行上,如果是这种情况,我希望它自动换行到多行.
我有一个字符串args[0]
.
到目前为止,这是我的代码:
static void Main(string[] args)
{
string latestversion = args[0];
// create reader & open file
using (StreamReader sr = new StreamReader("C:\\Work\\list.txt"))
{
while (sr.Peek() >= 0)
{
// code here
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想检查一下我的list.txt
文件是否包含args[0]
.如果是,那么我将创建另一个进程StreamWriter
来写一个字符串1
或0
文件.我该怎么做呢?
如何选择ComboBox的SelectedIndex = -1?
我编写了一个代码来自动化测试:
AutomationElement aeBuildMachine = null;
int count = 0;
do
{
Console.WriteLine("\nLooking for Build Machine Combo Box");
aeBuildMachine = aeTabitemmain.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ListBoxItem"));
if (aeBuildMachine == null)
throw new Exception("No Build Machine Combo Box");
else
Console.WriteLine("Found Build Machine Combo Box");
++count;
}
while (aeBuildMachine == null && count < 50);
Console.WriteLine("Selecting Build machine from combobox...");
SelectionItemPattern spBuildmachine = (SelectionItemPattern)aeBuildMachine.GetCurrentPattern(SelectionItemPattern.Pattern);
Run Code Online (Sandbox Code Playgroud)
我该如何使用它SelectionItemPattern
?
我想澄清ANT脚本中的if
和unless
语句
我有以下代码:
<condition property="hasExtensions">
<contains string="${Product_version}" substring="Extensions">
</condition>
<exec executable="${TrueCM_App}\ssremove.exe" unless="hasExtensions">
...
</exec>
Run Code Online (Sandbox Code Playgroud)
这是否意味着<exec>
如果Product_version
不包含字符串,上面会执行ssremove.exe "Extensions"
?
然后相反的情况如何:如果它包含字符串"Extensions"
?我的代码看起来像这样:
<condition property="hasExtensions">
<contains string="${Product_version}" substring="Extensions">
</condition>
<!-- here below it does not have the string "Extensions" -->
<exec executable="${TrueCM_App}\ssremove.exe" unless="hasExtensions">
...
</exec>
<!-- below is for if it has the string "Extensions" -->
<exec executable="${TrueCM_App}\ssremove.exe" if="hasExtensions">
...
</exec>
Run Code Online (Sandbox Code Playgroud) 在我的蚂蚁脚本中,我必须执行此操作 Read.exe
Read.exe将浏览版本控制并输出文本文件,大约需要一分钟才能完成.此文本文件作为.properties
antscript 的文件加载.但是,在我看来,我无法及时完成这项任务.到这个.properties
文件完成时,我已经执行了另一个需要该文件中某些属性的任务.因此我的问题是..如何在ANT脚本中添加延迟?
我有一个"保存"按钮,所以当用户点击时,它将保存xml文件(xml序列化).这里使用了savefiledialog,当我按下取消而不选择任何文件时出现"参数异常"并说"空路径名称不合法".我该如何处理这个例外?即使没有在savefiledialog中选择任何路径,我希望表单保持不变.非常感谢.
我的savefiledialog片段:
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string savepath;
SaveFileDialog DialogSave = new SaveFileDialog();
// Default file extension
DialogSave.DefaultExt = "txt";
// Available file extensions
DialogSave.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*";
// Adds a extension if the user does not
DialogSave.AddExtension = true;
// Restores the selected directory, next time
DialogSave.RestoreDirectory = true;
// Dialog title
DialogSave.Title = "Where do you want to save the file?";
// Startup directory
DialogSave.InitialDirectory = @"C:/";
DialogSave.ShowDialog();
savepath = DialogSave.FileName;
DialogSave.Dispose(); …
Run Code Online (Sandbox Code Playgroud) 我有3个标签项要实现.程序执行时,我希望用户只能看到tab1并隐藏选项卡2和选项卡3.
程序执行时会发生类似这样的事情:
public Window1()
{
InitializeComponent();
// I need tabs 2 and 3 to be hidden
}
Run Code Online (Sandbox Code Playgroud)
然后我在选项卡1中有一个按钮.当用户单击此按钮时,选项卡2显示但仍隐藏选项卡3
private void Button1_Click(object sender, RoutedEventArgs e)
{
tabcontrol1.SelectedIndex = 1;
//need some code to show tab 2
}
Run Code Online (Sandbox Code Playgroud)
我在选项卡2中有一个按钮来显示选项卡3,然后所有选项卡都可见
private void Button2_Click(object sender, RoutedEventArgs e)
{
tabcontrol1.SelectedIndex = 2;
// need some code to show tab 3
}
Run Code Online (Sandbox Code Playgroud)
我的XAML代码:
<TabControl Name="Tabcontrol1" Margin=" 5" SelectedIndex="0">
<TabItem Header="Directories">
<Grid Width="1185" Height="945" Background="White" >
<Label Height="28" HorizontalAlignment="Right"
Margin="0,0,25,0" Name="label11" VerticalAlignment="Top"
Width="120">Step 1 of 2</Label>
</Grid …
Run Code Online (Sandbox Code Playgroud) 我有两个文本框.如果textbox.text中的1为空,则MessageBox将显示提示用户他们没有完全输入字段.但它不起作用......
这是代码:
private void tab1nextButton_Click(object sender, RoutedEventArgs e)
{
if ((AntcbatchpathTextBox.Text == null) || (MasterbuildpropertiespathTextBox.Text == null))
{
System.Windows.MessageBox.Show("You have not specified the paths completely!");
}
else
{
Tabitem2.Visibility = Visibility.Visible;
Tabcontrol1.SelectedIndex = 1;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图添加断点来检查立即值.当Textbox.Text中的任何一个为空时,立即值分别为"".我的代码有什么问题吗?
有没有办法,我可以删除属性"只读"?
我试过这个:
var di = new DirectoryInfo("C:\\Work");
di.Attributes &= ~FileAttributes.ReadOnly;
Run Code Online (Sandbox Code Playgroud)
但它不能完成这项工作