小编N.D*_*N.D的帖子

以编程方式重命名计算机c#.net

我需要通过.net应用程序重命名我的电脑.我试过这段代码:

public static bool SetMachineName(string newName)
{
    MessageBox.Show(String.Format("Setting Machine Name to '{0}'...", newName));

    // Invoke WMI to populate the machine name
    using (ManagementObject wmiObject = new ManagementObject(new ManagementPath(String.Format("Win32_ComputerSystem.Name='{0}'",System.Environment.MachineName))))
    {
        ManagementBaseObject inputArgs = wmiObject.GetMethodParameters("Rename");
        inputArgs["Name"] = newName;

        // Set the name
        ManagementBaseObject outParams = wmiObject.InvokeMethod("Rename",inputArgs,null);

        uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
        if (ret == 0)
        {
            //worked
            return true;
        }
        else
        {
            //didn't work
            return false;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

我试过这个:

using System.Runtime.InteropServices;

[DllImport("kernel32.dll")]
static extern bool SetComputerName(string lpComputerName);

public static bool SetMachineName(string …
Run Code Online (Sandbox Code Playgroud)

.net c# wmi kernel32

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

Linq to SQL创建表

我需要编写一个WPF(4.0)应用程序,它有一个DB但没有表格.应用程序必须在数据库中创建一些表,然后开始使用它们.我想知道,有没有办法在Linq to SQL中做到这一点?

.net wpf linq-to-sql c#-4.0

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

Thread.Sleep c #.NET

我想把一个线程睡觉,我没有睡眠方法.

我用过System.Threading.

在我的代码中我写道:

Thread t = new Thread(StartPointMethod);
t.
Run Code Online (Sandbox Code Playgroud)

在方法列表中没有睡眠....

可能是什么问题呢?

.net c# multithreading

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

DateTime AM/PM格式转换为24h格式

我有一个日期时间,它是AM/PM格式.我想将其转换为24h格式,我该怎么做?谢谢.

.net c# datetime

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

每秒加载新图像

我需要加载每秒(或两个)新图像.

以下代码不起作用:

System.Threading.Thread.Sleep(2000);
this.Image_LoadImage.Source = new BitmapImage(new Uri(@"D:\\connect2-1.gif"));
System.Threading.Thread.Sleep(2000);
this.Image_LoadImage.Source = new BitmapImage(new Uri(@"D:\\connect3-1.gif"));
Run Code Online (Sandbox Code Playgroud)

我看到的是该应用程序睡眠4秒,然后出现第二个图像.

我该怎么做?谢谢.

.net c# wpf multithreading image

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

选择单个单选按钮,wpf

我需要在我的窗口上放置3个单选按钮,并让用户只选择一个按钮.我做了一个ListBox并设置了Selection mode = Single但我仍然可以选择所有这些,我需要将每个项目包装成某些东西......我不知道是什么以及如何.有人可以帮忙吗?也许有另一种方式来呈现单选按钮并只选择一个...?

这是xaml -

<ListBox SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0" Margin="0,0,0,57" HorizontalAlignment="Right" Width="304" Height="146" VerticalAlignment="Bottom">
        <ListBoxItem>
            <RadioButton Content="Option 1" Margin="0,0,0,10" Height="16" HorizontalAlignment="Left"  Name="radioButton1" VerticalAlignment="Top" FontSize="12" />
        </ListBoxItem>
        <ListBoxItem>
            <RadioButton Content="Option 2" Margin="0,0,0,10" Height="16" HorizontalAlignment="Left"  Name="radioButton2" VerticalAlignment="Top" FontSize="12" />
        </ListBoxItem>
        <ListBoxItem>
            <StackPanel Orientation="Horizontal" Height="90">
                <RadioButton Content="Another : " Checked="radioButton4_Checked" Height="16" HorizontalAlignment="Left"  Name="radioButton4" VerticalAlignment="Top" FontSize="12" />
                <TextBox Width="225" Name="TextBox_AnotherReason" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"/>
            </StackPanel>
        </ListBoxItem>
    </ListBox> 
Run Code Online (Sandbox Code Playgroud)

.net c# wpf listbox radio-button

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

ListBox只显示一个项目

我有一个ListBox带字符串的类.每次用户单击应用程序中的添加按钮时,我都会创建该类的新实例并将其添加到绑定到的列表中ListBox.第一次单击添加按钮时,列表框显示第一个项目,但下次没有显示两个项目.

XAML - 这是ListBox:

<ListBox Name="ListBox_BinsRegion" Height="181" Margin="233,16,6,94" Width="253" Background="Transparent" BorderThickness="1" BorderBrush="Black" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding}"/> 
Run Code Online (Sandbox Code Playgroud)

背后的代码:

List<Class_ListViewItem> List_ListBoxItems = new List<Class_ListViewItem>();

 private void Button_Add_Click(object sender, RoutedEventArgs e)
    {
        Class_ListViewItem item = new Class_ListViewItem();
        item.WH = this.comboBox_WareHouseBinsRegionDefinition.SelectedItem.ToString();
        item.XXFrom = textBox_XXFrom.Text;
        item.XXTo = textBox_XXTo.Text;
        item.YYFrom = textBox_YYFrom.Text;
        item.YYTo = textBox_YYTO.Text;
        item.Z = textBox_ZFrom.Text;

        List_ListBoxItems.Add(item);

        ListBox_BinsRegion.DataContext = List_ListBoxItems;
    }
Run Code Online (Sandbox Code Playgroud)

我的错误在哪里?

.net c# wpf xaml listbox

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

标签 统计

.net ×7

c# ×6

wpf ×4

listbox ×2

multithreading ×2

c#-4.0 ×1

datetime ×1

image ×1

kernel32 ×1

linq-to-sql ×1

radio-button ×1

wmi ×1

xaml ×1