小编Spe*_*cer的帖子

naudio从麦克风录制声音然后保存

我在使用naudio和保存录音方面遇到了一些问题.我目前使用的代码可以保存wav文件,但是当我打开它时,Windows Media Player会返回错误:"Windows Media Player在播放文件时遇到问题"

我有两个按钮,一个"记录"按钮,在按下后变成停止按钮.我有一个"保存"按钮,单击该按钮可将录像保存到sample.wav.

NAudio.Wave.WaveIn sourceStream = null;
NAudio.Wave.DirectSoundOut waveOut = null;
NAudio.Wave.WaveFileWriter waveWriter = null;

private void recordButton_Click(object sender, EventArgs e)
{
    int deviceNumber = sourceList.SelectedItems[0].Index;

    sourceStream = new NAudio.Wave.WaveIn();
    sourceStream.DeviceNumber = deviceNumber;
    sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

    NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

    waveOut = new NAudio.Wave.DirectSoundOut();
    waveOut.Init(waveIn);

    sourceStream.StartRecording();
    waveOut.Play();

    recordButton.Visible = false;
    stopRecord.Visible = true;
}

private void saveResponse_Click(object sender, EventArgs e)
{
    int deviceNumber = sourceList.SelectedItems[0].Index;

    string saveLocation = "c:\\wav\\sample.wav";

    sourceStream = new …
Run Code Online (Sandbox Code Playgroud)

c# naudio

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

自定义组合框边界闪烁

我在一些c#WinForms表单字段中使用了较暗的样式.组合框特别类似于:

在此输入图像描述

我正在使用此Stack答案中的代码:Combobox borderstyle

不幸的是,我遇到了闪烁边框的问题.当我将鼠标放入或鼠标悬停在组合框上时,它将以白色边框快速闪烁.

有没有办法解决这个问题?我尝试过使用DoubleBuffer,但它没有缓解这个问题.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;

namespace FlattenCombo
{
    public class FlattenCombo : ComboBox
    {
        private Brush BorderBrush = new SolidBrush(SystemColors.WindowFrame);
        private Brush ArrowBrush = new SolidBrush(SystemColors.ControlText);
        private Brush DropButtonBrush = new SolidBrush(SystemColors.Control);

        private Color _ButtonColor = SystemColors.Control;
        public Color ButtonColor
        {
            get { return _ButtonColor; }
            set
            {
                _ButtonColor = value;
                DropButtonBrush = new SolidBrush(this.ButtonColor);
                this.Invalidate();
            }
        }

        private Color _borderColor …
Run Code Online (Sandbox Code Playgroud)

c# combobox winforms

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

在 C# 中更改组合框下拉列表边框颜色

是否可以在 C# 中更改组合框下拉列表的边框颜色?

在此处输入图片说明

我想将白色边框更改为更深的阴影以匹配深色方案。我搜索了 .net 文档并找到了该DropDownList.BorderStyle属性。但是,我不确定这是否有效。我正在使用 WinForms。

这是我用于组合框的类:

public class FlattenCombo : ComboBox
{
    private Brush BorderBrush = new SolidBrush(SystemColors.WindowFrame);
    private Brush ArrowBrush = new SolidBrush(SystemColors.ControlText);
    private Brush DropButtonBrush = new SolidBrush(SystemColors.Control);

    private Color _borderColor = Color.Black;
    private ButtonBorderStyle _borderStyle = ButtonBorderStyle.Solid;
    private static int WM_PAINT = 0x000F; 

    private Color _ButtonColor = SystemColors.Control;

    public Color ButtonColor
    {
        get { return _ButtonColor; }
        set
        {
            _ButtonColor = value;
            DropButtonBrush = new SolidBrush(this.ButtonColor);
            this.Invalidate();
        }
    }

    protected override void WndProc(ref …
Run Code Online (Sandbox Code Playgroud)

c# combobox winforms

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

c#将选定的列表框项目复制到字符串中

我在将列表框中的选定值转换为字符串时遇到了一些问题.

列表框包含多个值,我们称之为AZ.基本上,我想将所选项目复制到一个字符串中.

var listarray = new System.Collections.ArrayList(listboxName.SelectedItems);

string myval = "";

foreach (var arr in listarray)
{
    myval = dep.ToString();
    Console.WriteLine(myval); // this shows all the selected values
}

string finalStr = "some text before the values" + myval;
Console.WriteLine(finalStr);
Run Code Online (Sandbox Code Playgroud)

我希望字符串显示"值A,B,C,D ......之前的一些文本",而是输出"值A之前的一些文本"

最后一个Console.WriteLine只显示一个值而不是所有选定的值.我已经尝试finalStrforeach循环内部添加,但这会创建多个实例,finalStr而不是只有一个具有多个数组值的字符串.

c# foreach listbox

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

没有配置文件的WCF /服务引用

我在使用我的c#应用程序设置Microsoft Translator SOAP Service时遇到问题,而不依赖于它生成的app.config文件.

app.config文件包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_LanguageService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://api.microsofttranslator.com/V2/soap.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
                contract="Soap.LanguageService" name="BasicHttpBinding_LanguageService" />
        </client>
    </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

在参考这个Stack答案时,我使用了以下方法:

internal static Soap.LanguageServiceClient CreateWebServiceInstance()
{
    BasicHttpBinding binding = new BasicHttpBinding();
    binding.Name = "BasicHttpBinding_LanguageService";
    binding.TextEncoding = System.Text.Encoding.UTF8;
    return new Soap.LanguageServiceClient(binding, new EndpointAddress("http://api.microsofttranslator.com/V2/soap.svc"));
}
Run Code Online (Sandbox Code Playgroud)

但是,即使我CreateWebServiceInstance()在执行翻译服务之前打电话,我也会得到这个未处理的异常:

Could not find default endpoint element that references contract 'Soap.LanguageService' in the ServiceModel client configuration section. This might …
Run Code Online (Sandbox Code Playgroud)

c# wcf

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

将数据属性添加到表格单元格

是否可以使用jquery将数据属性添加到表格单元格?我有以下但它没有添加数据属性td.

$("td.row").each(function( index ) {
  $(this).data("rowid",index);
});
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

javascript jquery

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

标签 统计

c# ×5

combobox ×2

winforms ×2

foreach ×1

javascript ×1

jquery ×1

listbox ×1

naudio ×1

wcf ×1