小编Uwe*_*eim的帖子

C#如何在每个单词之后放置一个逗号,但列表中的最后一个

我完全不熟悉C#并且在学习的过程中学习.我遇到了一个问题,我希望有经验的程序员可以提供帮助.我在表单中添加了一个CheckedListBox,并添加了一个包含6个项目的集合.除了最后选择的项目之外我还需要一个逗号放在旁边,所以我的问题是:我怎么能告诉C#不要在最后选择的项目旁边放一个逗号?

foreach (object itemChecked in RolesCheckedListBox.CheckedItems)
{
    sw.Write(itemChecked.ToString() + ",");
}
Run Code Online (Sandbox Code Playgroud)

感谢您的任何帮助!担

c#

23
推荐指数
3
解决办法
2万
查看次数

文本框填充

我通过互联网搜索,我必须使用错误的关键字,因为我找不到任何东西.我想创建一个文本框,其文本从远离左侧开始.

http://dab.biz/images/screenie/2011-02-04_1316.png

就像那样.

.net c# textbox padding winforms

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

NuGet以代码-1退出 - 结果导致构建失败

我已经在VS2012中通过Package Manager安装了dotless到现有的混合C#解决方案(类库和MVC2应用程序),但是现在当我构建它(F5)时,我得到以下两个错误:

命令""C:\ @ GitRepos\EBS\SolutionFiles\.nuget \nuget.exe"install"C:\ @ GitRepos\EBS \\ packages.config"-source"" - o"C:\ @ GitRepos\EBS\SolutionFiles\packages""以代码-1退出.

该系统找不到指定的路径.

在向解决方案添加无点之后,添加了具有"NuGet.exe和"NuGet.targets"的".nuget"文件夹.

我还尝试将dotless添加到一个新的MVC2项目中,除了必须在web.config中添加一个mime类型之外它一切正常.但是没有".nuget"文件夹.

我还注意到,如果我创建一个新的NServiceBus解决方案(安装后),也会发生同样的情况.消息中的路径发生更改但错误相同.

如果我服用

"C:\ @ GitRepos\EBS\SolutionFiles\.nuget \nuget.exe"安装"C:\ @ GitRepos\EBS \\ packages.config"-source"" - o"C:\ @ GitRepos\EBS\SolutionFiles \套餐"

并通过命令提示符运行它然后我得到:

package.config中列出的所有软件包都已安装.

c# build nuget asp.net-mvc-2 dotless

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

头部重复的样式和许多<style>元素

我对angular-material2组件非常满意,但有一些我不理解的奇怪行为,并且他们没有适当的文档,特别是对于丰富和定制他们的组件.

我的项目看起来像:

.src
  --app
    --components
      --login-component
           login-component.html
           login-component.scss
           login-component.js
      --login-component
            home-component.html
            home-component.scss
            home-component.js
       --and so on ...
    app.component.html
    app.component.scss
    app.component.ts
    app.module.ts
    app.routing.ts
    --assets
    --environments
    --scss
      styles.scss
      _material2-theme.scss
      _variables-scss
      _utilities.scss
      _reset.scss
   favicon
   index.html
   and so on ....
Run Code Online (Sandbox Code Playgroud)

在angular-cli.json中,我修改了样式以查看scss/style.scss

...
"styles": [
        "scss/styles.scss"
      ]
...
Run Code Online (Sandbox Code Playgroud)

_material2-theme.scss看起来像:

//////////////////////* THEMES */ Custom Blue Theme*/
@import '~@angular/material/theming';
@include mat-core();
$app-primary: mat-palette($mat-light-blue);
$app-accent:  mat-palette($mat-light-blue, A200, A100, A400);
$app-theme:   mat-light-theme($app-primary, $app-accent);
@include angular-material-theme($app-theme);

/*default palette forground/background*/
$light-foreground-palette: map-get($app-theme, foreground);
$light-background-palette: map-get($app-theme, background);

$primary: map-get($app-theme, primary);
$accent: map-get($app-theme, …
Run Code Online (Sandbox Code Playgroud)

html javascript angular-material2 angular

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

Windows .NET Core 不支持密码解密?

我最近将一个私有 NuGet 存储库转换为需要身份验证。

为了构建使用该存储库的项目,我将身份验证添加到了本地 NuGet.Config 中NuGet Sources add -name [repo_name] -Source [source_url] -UserName [username] -Password [password]

现在,当我尝试运行时出现以下错误dotnet restore

此平台的 .NET Core 不支持密码解密。以下源使用加密密码:“nuget-sdet”。您可以使用明文密码作为解决方法。

我知道这在 Linux 上不受支持,但我在 Windows Server 2012 R2 上运行它。

它在非常旧的 .NET Core 版本上运行1.0.0-preview2-003121 .

Windows 上较新版本的 .NET Core 是否支持密码解密?

或者我是否陷入以明文形式存储密码或重新启用对提要的匿名访问之间的困境?

nuget-package-restore .net-core

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

Visual Studio 2022 关闭灰色建议

如何在 Visual Studio 2022 中关闭灰色建议,但保留下表?

灰色建议

c# visual-studio-2022

23
推荐指数
2
解决办法
8674
查看次数

得到错误TS2304:找不到名称'Buffer'

我正在尝试使用TypeScript在NodeJS中执行base64编码.

以下代码在JavaScript中正常工作.

当我在TypeScript中编写相同的东西并进行编译时,我得到Buffer is not find错误.

var base64Policy = new Buffer(stringPolicy, 'utf-8').toString('base64');
Run Code Online (Sandbox Code Playgroud)

有人可以帮我在TypeScript中做同样的事情.

types node.js typescript typescript1.4 typescript1.8

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

typeof generic和casted类型

假设我们有通用方法:

public void GenericMethod<T>(T item)
{
    var typeOf = typeof(T);
    var getType = item.GetType();
}
Run Code Online (Sandbox Code Playgroud)

我们使用以下参数调用它:

GenericMethod(1)
GenericMethod((object) 1)
Run Code Online (Sandbox Code Playgroud)

结果是:

typeOf = System.Int32
getType = System.Int32
Run Code Online (Sandbox Code Playgroud)

typeOf = System.Object
getType = System.Int32
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么输入到对象的typeof整数返回System.Object,但.GetType()返回System.Int32?

c# generics

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

找不到配置文件“secrets.json”并且不是可选的(.NET 6)

当不应预期有 Secrets.json 文件时,CI/CD 管道中会生成用户机密错误。

脚步:

  1. 创建.NET 5项目
  2. 添加了用户机密。
  3. 代码在本地和 CI/CD 管道中运行。
  4. 升级到 .NET 6 项目(并预览 NuGet 6.* 包)

代码在本地运行,但在 CI/CD 管道中失败,并出现错误:

“找不到配置文件‘secrets.json’并且不是可选的。”

预期的:

代码在没有 Secrets.json 文件的情况下运行配置 .NET 6,Microsoft.Extensions.Configuration.UserSecrets:6.0.0-preview.1.21102.12

回归?这适用于 .NET 5,Microsoft.Extensions.Configuration.UserSecrets:5.0.0.*

System.IO.FileNotFoundException: The configuration file 'secrets.json' was not found and is not optional. The physical path is '/home/runner/work/UserSecretsRegression/UserSecretsRegression/UserSecrets/UserSecrets.Tests/bin/Release/net6.0/secrets.json'.
  Stack Trace:
      at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at UserSecrets.Tests.UnitTest1.TestMethod1() in /home/runner/work/UserSecretsRegression/UserSecretsRegression/UserSecrets/UserSecrets.Tests/UnitTest1.cs:line 13
Run Code Online (Sandbox Code Playgroud)

.net c# .net-6.0

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

绘制透明按钮

我正在尝试在C#(.NET 3.5 SP1)中创建一个透明按钮,以便在我的WinForms应用程序中使用.我已经尝试了一切让按钮变得透明(它应该显示按钮下方的渐变背景)但它只是不起作用.

这是我正在使用的代码:

public class ImageButton : ButtonBase, IButtonControl
{
    public ImageButton()
    {
        this.SetStyle(
            ControlStyles.SupportsTransparentBackColor | 
            ControlStyles.OptimizedDoubleBuffer | 
            ControlStyles.AllPaintingInWmPaint | 
            ControlStyles.ResizeRedraw | 
            ControlStyles.UserPaint, true);
        this.BackColor = Color.Transparent;
    }

    protected override void OnPaint(PaintEventArgs pevent)
    {
        Graphics g = pevent.Graphics;
        g.FillRectangle(Brushes.Transparent, this.ClientRectangle);
        g.DrawRectangle(Pens.Black, this.ClientRectangle);
    }


    // rest of class here...

}
Run Code Online (Sandbox Code Playgroud)

问题是该按钮似乎是从某个地方抓取随机UI内存并从Visual Studio的UI中填充一些缓冲区(在设计模式下).在运行时它会抓住一些零缓冲区并且完全是黑色的.

我的最终目标是在隐形按钮而不是矩形上绘制图像.然而,这个概念应该保持不变.当用户将鼠标悬停在按钮上时,则绘制按钮类型的形状.

有任何想法吗?

编辑:谢谢大家,以下为我工作:

public class ImageButton : Control, IButtonControl
{
    public ImageButton()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        SetStyle(ControlStyles.Opaque, true);
        SetStyle(ControlStyles.ResizeRedraw, true);
        this.BackColor = Color.Transparent;

    }

    protected override void OnPaint(PaintEventArgs pevent) …
Run Code Online (Sandbox Code Playgroud)

c# gdi+ button winforms

21
推荐指数
2
解决办法
5万
查看次数