所有(这是回归基础!),我从SQL Server中获取了一串信息.字符串是这样的
Hello, my name is Frank Butcher\n\n
and I work at Watford Car lot,
and I am 65 years old.
Run Code Online (Sandbox Code Playgroud)
该消息将被拉入消息框以提供有关进程的信息.我用它读了字符串
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = 0;
cmd.CommandText = strSQL;
strResult = cmd.ExecuteScalar().ToString();
Run Code Online (Sandbox Code Playgroud)
这会得到字符串,但当我把它放到我的文本框中时,显示的消息\n\n没有所需的双NewLine.
我试过用
strResult = strResult.Replace("\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
在字符串上,但这没有帮助.我精神错乱,我做错了什么?
谢谢你的时间.
我有以下SQL Server存储过程:
CREATE PROCEDURE ispsDcOhcAgg @TmpTableName NVARCHAR(50), @ListItem NVARCHAR(50)
AS
IF EXISTS (SELECT name
FROM sys.tables
WHERE name = @TmpTableName)
DROP TABLE @TmpTableName; -- This will not work.
GO
Run Code Online (Sandbox Code Playgroud)
这显然不起作用(参见上面的snippit中的评论).我发现解决这个问题的唯一(也是非常丑陋的)方法是执行以下操作
CREATE PROCEDURE ispsDcOhcAgg @TmpTableName NVARCHAR(50), @ListItem NVARCHAR(50)
AS
DECLARE @SQL NVARCHAR(4000)
SET @SQL = N'IF EXISTS (SELECT name ' +
N'FROM sys.tables ' +
N'WHERE name = N' + N'''' + @TmpTableName + N''') ' +
N'DROP TABLE ' + @TmpTableName + N';'
EXEC sp_executesql @SQL;
GO
Run Code Online (Sandbox Code Playgroud)
真正发臭和大型存储过程,这是可怕的!
还有另一种我不知道的做法吗?
谢谢你的时间.
所有,我有一个深刻的外观,但似乎无法找到我要找的东西.我想要改变ComboBoc控件的选择颜色(理想情况下不必对控件进行子类化).我虽然做了以下工作,但这个事件甚至没有解雇
private void comboBoxDb_DrawItem(object sender, DrawItemEventArgs e)
{
ComboBox combo = sender as ComboBox;
e.Graphics.FillRectangle(new SolidBrush(combo.BackColor), e.Bounds);
string strSelectionColor = @"#99D4FC";
Color selectionColor =
System.Drawing.ColorTranslator.FromHtml(strSelectionColor);
e.Graphics.DrawString(combo.Items[e.Index].ToString(),
e.Font,
new SolidBrush(selectionColor),
new Point(e.Bounds.X, e.Bounds.Y));
}
Run Code Online (Sandbox Code Playgroud)
但这个事件甚至没有开火.我在这做错了什么?
谢谢你的时间.
编辑.尽管非触发是由于未设置@Teppic正确指出的ComboBox的DrawMode属性引起的,但这仍然没有按照我的要求进行.我想设置选择颜色,我上面做了什么(我在这里阻止了名字)

而我想更改控件的蓝色突出显示,如此处所示.

总而言之,我已经预装了大量的WinForms,这个错误很奇怪,因为我之前没有遇到它.此表单是此项目中的30+之一,并且是唯一一个缩放在不同屏幕分辨率和字体缩放时表现奇怪的表单.
我知道这个AutoScaleMode属性,大部分时间我都设置了它Font以防止我在这里发生的错误.当我在1920x1080显示器上启动此表格时,它很好

但是在1920x1200显示器上启动表格,组框似乎调整大小

这迫使屏幕上的按钮导致一般的丑陋.如果我将默认的OS字体从125%更改为100%,我也可以在我的1980x1080显示器上进行此操作.
顶部组框锚定(左,右,顶部),底部组框锚定(左,右,顶部,底部).该方式被设定为和AutoScaleMode的Font.其他控制不是 AutoSized.
有什么问题,如何解决?
谢谢你的时间.
编辑:设计器文件如下.
namespace IPACost
{
partial class CreateNationalDbForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows …Run Code Online (Sandbox Code Playgroud) 为了试图解决这个问题,我在DataGrid Scroll之后将Binding Selected RowCount绑定到TextBlock而不是Firing OnPropertyChanged ; 即TextBlock用DataGrid滚动时的当前所选行数更新a .我试图介绍AttachedCommandBehaviour由Marlon Grech设计的[一个惊人的类结构,允许您将命令绑定到给定控件的特定事件].
现在对于这个问题,使用这个AttachedCommandBehaviour,我怎样才能得到TextBlock基于a DataGrid的更新SelectionChangedProperty?
XMAL是
<Window x:Class="ResourceStudio.Views.AddCultureWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModels="clr-namespace:ResourceStudio.ViewModels"
xmlns:converters="clr-namespace:ResourceStudio.Converters"
xmlns:dataAccess="clr-namespace:ResourceStudio.DataAccess"
xmlns:attachedCommand="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
Title="Add Culture"
Height="510" Width="400"
WindowStartupLocation="CenterOwner"
VerticalContentAlignment="Stretch"
MinWidth="380" MinHeight="295">
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15*"/>
<ColumnDefinition Width="377*"/>
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="1">
<Grid>
<Grid.Resources>
<converters:EnumToBooleanConverter x:Key="enumToBooleanConverter"/>
<Style x:Key="HyperlinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> …Run Code Online (Sandbox Code Playgroud) DataGrid当用户单击最后一行以添加新行时,标准WPF中存在已知错误.
抛出异常是因为在处理MS.Internal.NamedObject表示'NewItemPlaceholder'的方法时,ConvertBack方法(在默认转换器上)失败.如果CanUserAddRows设置为True(并且集合支持它),则此实例用于表示空白的"新行".实际上,在尝试跟踪绑定失败时,似乎实际上在异常处理程序中抛出了FormatException.有关更多信息,请参阅Nigel Spencer的博客.
基本上解决方法是在SelectedItem绑定上添加转换器:
public class IgnoreNewItemPlaceholderConverter : IValueConverter
{
private const string newItemPlaceholderName = "{NewItemPlaceholder}";
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value.ToString() == newItemPlaceholderName)
value = DependencyProperty.UnsetValue;
return value;
}
}
Run Code Online (Sandbox Code Playgroud)
在XAML中使用它的一个例子是:
<Window.Resources>
<converters:IgnoreNewItemPlaceHolderConverter x:Key="ignoreNewItemPlaceHolderConverter"/>
</Window.Resources>
<toolkit:DataGrid ItemsSource="{Binding Persons}"
AutoGenerateColumns="False"
SelectedItem="{Binding SelectedPerson, Converter={StaticResource ignoreNewItemPlaceHolderConverter}}"
IsSynchronizedWithCurrentItem="True">...</toolkit:DataGrid>
Run Code Online (Sandbox Code Playgroud)
我的问题是我试图对我自己实施这个'修复'/'黑客' DataGrid …
我有一个IEnumerable<double>数据样本.我想计算信号/数据的90%置信区间.我有MathNET库,但我对如何正确使用库感到困惑.根据我的数据,我们的想法是返回两个包含原始信号置信区间的附加数据数组
using MathNet.Numerics.Statistics;
using MathNet.Numerics.Distributions;
public static List<double[]> ConfidenceIntervals(IEnumerable<double> sample, double interval)
{
Contract.Requires(interval > 0 && interval < 1.0);
int sampleSize = sample.Count();
double alpha = 1.0 - interval;
double mean = sample.Mean();
double sd = sample.StandardDeviation();
double t, mu;
double[] upper = new double[sampleSize];
double[] lower = new double[sampleSize];
StudentT studentT = new StudentT(mean, alpha, sampleSize - 1);
int index = 0;
foreach (double d in sample)
{
t = studentT.CumulativeDistribution(d);
double tmp = …Run Code Online (Sandbox Code Playgroud) 我在使用标准的Windows Forms TreeView时遇到了麻烦; 特别是当树视图没有焦点时,默认控件用于渲染所选节点的颜色.这是浅灰色,在某些屏幕上几乎看不见.随后,我已经将TreeView子类化并覆盖了TreeView OnDrawNode事件,以便按照我的意愿为我的节点着色.这很好用,但现在'HotTracking'(当鼠标在给定的树节点上时激活突出显示)被我的自定义OnDrawNode事件覆盖.我不太熟悉这些Graphics类,并想知道如何修改我当前的子类以包含热跟踪?我知道我可以使用,e.Graphics.DrawLine(Pen pen, Point p1, Point p2);但这会变得混乱,有更简单的方法吗?
这是现有的代码:
class CustomTreeView : TreeView
{
public CustomTreeView()
{
this.DrawMode = TreeViewDrawMode.OwnerDrawText;
}
// Override the drawMode of TreeView.
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
{
TreeNodeStates treeState = e.State;
Font treeFont = e.Node.NodeFont ?? e.Node.TreeView.Font;
// Colors.
Color foreColor = e.Node.ForeColor;
string strDeselectedColor = @"#6B6E77", strSelectedColor = @"#94C7FC"; //@"#1ABEE8"; //@"#2FC0EE"; //@"#3A8FEA";
Color selectedColor = System.Drawing.ColorTranslator.FromHtml(strSelectedColor);
Color deselectedColor = System.Drawing.ColorTranslator.FromHtml(strDeselectedColor);
// New brush.
SolidBrush …Run Code Online (Sandbox Code Playgroud) 我已经能够使用以下命令在Windows Vista上编译boost:
bootstrap.bat
bjam.exe --with-filesystem --with-thread --toolset=msvc
Run Code Online (Sandbox Code Playgroud)
但是,当我在Windows 7上发出相同的命令时,我得到了这个:
'failed to write output file 'bin.v2\libs\thread\build\msvc-8.0\release\link-static\threading-multi\libboost_thread-vc80-mt-1_48.lib.rsp'!'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
全部,我想为RichTextBoxWinForm 添加一个自定义TabPage.我尝试过以下代码说明的各种事情
TabPage tmpTabPage = new TabPage("Test");
tabControl1.TabPages.Add(tmpTabPage);
CustomRichTextBox tmpRichTextBox = new CustomRichTextBox();
tmpRichTextBox.LoadFile(@"F:\aaData\IPACostData\R14TData\ACT0\1CALAEOSAudit_log.rtxt");
// Attempted FIX.
tabControl1.SuspendLayout();
tabControl1.TabPages["Test"].Controls.Add(tmpRichTextBox); // This throws a NullReferenceException??
tabControl1.ResumeLayout();
tmpRichTextBox.Parent = this.tabControl1.TabPages["test"];
tmpRichTextBox.WordWrap = tmpRichTextBox.DetectUrls = false;
tmpRichTextBox.Font = new Font("Consolas", 7.8f);
tmpRichTextBox.Dock = DockStyle.Fill;
tmpRichTextBox.BringToFront();
Run Code Online (Sandbox Code Playgroud)
在我添加"aAttempted FIX"之前,代码将毫无例外地运行但CustomRichTextBox不会出现.现在我得到了NullReferenceException,我对两种情况感到困惑.我在这做错了什么?