小编Jan*_*nik的帖子

RichTextBox - TextRanges 之间的换行符

我在使用 RichTextBox 时遇到一个小问题。

我正在尝试进行某种聊天,包括每行使用不同的颜色,这就是为什么我使用 RichTextBox 而不是普通的聊天框。但我在换行方面遇到了一些麻烦。

我的目标是实现这种格式:

Player 1: Hello world!
System Bot: The game has begun!
Player 2: sup man?
Player 1: Nothing
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的代码到目前为止还没有完成它的工作:

public void Handle(NewMessageMessage message)
{
    var messageStr = message.Message;

    var range = new TextRange(ChatMessages.ContentEnd, ChatMessages.ContentEnd);

    switch (message.Type)
    {
        case MessageType.SystemInformation:
            range.Text = string.Concat("System-Bot: ", messageStr, "\r\n");
            range.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Color.FromArgb(255, 255, 150, 0)));
            break;
        case MessageType.SystemWarning:
            range.Text = string.Concat("System-Bot: ", messageStr, "\r\n");
            range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
            break;
        case MessageType.PlayerMessage:
            range.Text = string.Concat(messageStr, "\r\n");
            range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
            break;
    }

    NotifyOfPropertyChange(() …
Run Code Online (Sandbox Code Playgroud)

wpf richtextbox

3
推荐指数
1
解决办法
3141
查看次数

在SUM()之前舍入值

我们的客户在其输入字段中使用公式。这就是为什么它们的值有时包含小数位的原因。我们无法四舍五入每个字段,因为它们的公式和输入会覆盖它。

我有一个字段,该字段要求数字不带小数位。是否有可能对ROUNDED值进行SUM()运算,类似于使用一系列输入的ROUND()函数?

excel

3
推荐指数
1
解决办法
5万
查看次数

如何将时区添加到 DateTime.UtcNow?

我有一个从客户那里收到的时区,我用它来设置到期日期时间,以便它相当于客户时区中的“月末”的 UTC。

我试过这个:

var current = timezone.ToUniversalTime(DateTime.UtcNow);
Run Code Online (Sandbox Code Playgroud)

但无法工作。有人可以帮我吗?

c# datetime

3
推荐指数
1
解决办法
3214
查看次数

静态覆盖/抽象方法 - 任何好的解决方法?

我有一个抽象的基本配置类和两个实现:

public abstract class BaseConfiguration
{
}

public class LoginConfiguration : BaseConfiguration
{
    public LoginConfiguration() 
    {
    }

    public string Name { get; set; }
    public string Password { get; set; }
}

public class TestConfiguration : BaseConfiguration
{
    public TestConfiguration()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我面临的问题:每个特定的类类型都有一个明确的文件名.这意味着LoginConfiguration有一个名为"login.xml"的文件名,TestConfiguration指向"test.xml".

我希望稍后用于反序列化的文件名:

static void Main(string[] args)
{
    LoginConfiguration login = ReadFromFile<LoginConfiguration>();
    Console.ReadLine();
}

private static TConfig ReadFromFile<TConfig>() where TConfig : BaseConfiguration
{
    //Something like this needs to be done here:
    string filename = TConfig.GetFilename();

    //Deserialize file and …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
128
查看次数

AppVeyor 的 .NET Core .csproj 补丁没有任何影响

这个周末我开始玩 AppVeyor。在我解决了其他一些问题之后,我目前陷入了版本修补。

我想要实现的是:我的正常主分支应该像 1.0.{build} 这样的版本,它工作正常。但是当涉及到 dev 分支时,每个构建(或者可以说是 nuget 包)都应该包含类似“-alpha”后缀的内容。

这是我目前的Appveyor.xml. 它目前提交到我的 dev-Branch 的根目录,master 分支目前没有 xml,我想先解决这个问题。

version: 1.0.{build}
image: Visual Studio 2017
configuration: Release
platform: Any CPU
dotnet_csproj:
  patch: true
  file: '**\*.csproj'
  version: '{version}'
  package_version: '{version}'
  assembly_version: '{version}'
  file_version: '{build}'
  informational_version: '{version}'
before_build:
- cmd: dotnet restore Kinoheld.Api.Client\Kinoheld.Api.Client.sln
build:
  verbosity: minimal
after_build:
- cmd: dotnet pack Kinoheld.Api.Client\Kinoheld.Api.Client\Kinoheld.Api.Client.csproj
artifacts:
- path: '**\*.nupkg'
deploy: off

for:
-
  branches:
    only:
      - dev

  dotnet_csproj:
    patch: true
    file: '**\*.csproj'
    version: '{version}-alpha'
    package_version: '{version}-alpha'
    assembly_version: …
Run Code Online (Sandbox Code Playgroud)

appveyor .net-standard

2
推荐指数
1
解决办法
302
查看次数

Get-WmiObject - 在 -filter 中使用 OR 运算符?

我必须做一些 powershell 脚本修改,但我无法在我的开发机器上正确测试。

这就是为什么我想知道我是否可以ORGet-WmiObject -filter操作中使用 -Operator?

目前我们使用

(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%'" ...).Uninstall()
Run Code Online (Sandbox Code Playgroud)

但最近我们将应用程序的名称从 重命名ApplicationName1NewName. 这就是为什么我想添加另一个条件,如下所示:

(Get-WmiObject -Class Win32_Product -Filter "Name like 'ApplicationName1 Client%' OR Name like 'NewName Client%'" ...).Uninstall()
Run Code Online (Sandbox Code Playgroud)

我的问题是:

这是过滤器的有效语法还是会引发异常/给出错误?如果出现错误,您将如何执行此操作?

powershell get-wmiobject

1
推荐指数
1
解决办法
1万
查看次数

将 ComboBox DataSource 设置为枚举并绑定 SelectedValue

我有点绝望,因为昨天它可以工作,但今天这不再有效,让我解释一下,我正在尝试做什么:

我想设置DataSourceComboBox所有枚举值在一个特定的枚举。就像这样:

cmbType.DataSource = m_addViewPresenter.Types;
Run Code Online (Sandbox Code Playgroud)

其中 Types 是 aBindingList并且正在像这样初始化:

public BindingList<MyEnum> Types
{
    get { return m_types; }
    set
    {
        m_types = value;
        OnPropertyChanged();
    }
}

[ImportingConstructor]
public AddViewPresenter()
{
    Types = new BindingList<MyEnum>(
              Enum.GetValues(typeof(MyEnum))
                         .Cast<MyEnum>().ToList());
}
Run Code Online (Sandbox Code Playgroud)

此外,我想将选择的当前项目绑定到一个属性。由于ComboBox.SelectedItem不触发 -INotifyProperty事件,我使用ComboBox.SelectedValue.

cmbType.Bind(m_addViewPresenter, c => c.SelectedValue, m => m.SelectedValue);

public static void Bind<TComponent, T>(
    this TComponent component, T value,
    Expression<Func<TComponent, object>> controlProperty, 
    Expression<Func<T, object>> modelProperty)
    where TComponent : IBindableComponent
    where T …
Run Code Online (Sandbox Code Playgroud)

c# data-binding combobox winforms

0
推荐指数
1
解决办法
2349
查看次数