17,740
社区成员
发帖
与我相关
我的任务
分享
Camera_Manage_Ctr MirrorWin = new Camera_Manage_Ctr();
MirrorWin.lstCameras.ItemsSource = GetCameras().DefaultView;
<UserControl x:Class="MultiCast.Cameras.Camera_Manage_Ctr"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="600" Height="540"
Loaded="OnLoaded"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*" />
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="2" Padding="10 10 5 10" Text="摄像机列表"/>
<ListView Grid.Row="1" Name="lstCameras" SelectedValuePath="CameraNo">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="序号" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=CameraNo,Mode=OneWay}" Width="40" Padding="5" TextAlignment="Center" ></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="摄像机名称" Width="300" DisplayMemberBinding="{Binding Path=CameraName,Mode=OneWay}" />
<GridViewColumn Header="是否启动激光" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=IsLight,Mode=OneWay,Converter={StaticResource bitConverter}}" Width="90" TextAlignment="Center" ></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="1" Grid.Column="1">
<Button Margin="10" Name="btnAdd" Padding="5" VerticalAlignment="Top" Click="btnAdd_Click">添 加</Button>
<Button Margin="10" Name="btnModify" Padding="5" VerticalAlignment="Top" Click="btnModify_Click">修 改</Button>
<Button Margin="10" Name="btnDelete" Padding="5" VerticalAlignment="Top" Click="btnDelete_Click">删 除</Button>
</StackPanel>
</Grid>
</UserControl>
//Open Add Camera win
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
Add_Camera_Dialog DialogAdd = new Add_Camera_Dialog();
DialogAdd.ShowDialog();
}
<Window x:Class="MultiCast.Cameras.Add_Camera_Dialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="AddDialog"
WindowStartupLocation="CenterScreen"
Title="添加摄像机" Height="180" Width="400">
<Grid Margin="5 10" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*" />
<ColumnDefinition Width="75*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30*" />
<RowDefinition Height="30*" />
<RowDefinition Height="40*" />
</Grid.RowDefinitions>
<Label Padding="10" HorizontalAlignment="Right" >摄像机名称</Label>
<Label Padding="10" Grid.Row="1" HorizontalAlignment="Right">是否启用激光</Label>
<TextBox Grid.Column="1" Margin="10,5" Padding="5 6 0 0" Name="tbCameraName" />
<CheckBox Grid.Column="1" Grid.Row="1" Margin="10" Name="cbxIsLight" HorizontalAlignment="Left" Width="13"></CheckBox>
<Button Margin="10,10,0,10" Name="btnAdd" Grid.Column="1" Grid.Row="2" Width="80" HorizontalAlignment="Left" Click="btnAdd_Click">添 加</Button>
<Button Margin="100,10,0,10" Name="btnCancel" Grid.Column="1" Grid.Row="2" Width="80" HorizontalAlignment="Left" Click="btnCancel_Click">取 消</Button>
</Grid>
</Window>
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
string cname = tbCameraName.Text;
int ischeck = 0;
if (cname == "")
{
MessageBox.Show("请输入摄像机名称", "操作失败");
return;
}
if (cbxIsLight.IsChecked == true)
{
ischeck = 1;
}
Model.Cameras cameraEntity = new MultiCast.Model.Cameras();
cameraEntity.CameraName = cname;
cameraEntity.IsLight = ischeck;
BLL.Cameras cameraClass = new MultiCast.BLL.Cameras();
if (cameraClass.GetCameraNo(cname) != 0)
{
MessageBox.Show("已存在同名摄像机", "操作失败");
return;
}
cameraClass.Add(cameraEntity);
MessageBox.Show("成功添加摄像机!", "操作成功");
Camera_Manage_Ctr MirrorWin = new Camera_Manage_Ctr();
MirrorWin.lstCameras.ItemsSource = GetCameras().DefaultView;
tbCameraName.Text = "";
cbxIsLight.IsChecked = false;
CloseWin();
}
子窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1 {
//定义委托
public delegate void ChangeTextHandler(string text);
public partial class ChildFrm : Form {
//定义事件
public event ChangeTextHandler ChangeTextEvent;
public ChildFrm() {
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="sender">事件源</param>
/// <param name="e">事件对象</param>
private void radioButton1_CheckedChanged(object sender, EventArgs e) {
RadioButton rdo = sender as RadioButton;
//引发事件
if (ChangeTextEvent != null) {
ChangeTextEvent(rdo.Text);
}
}
private void ChildFrm_MouseClick(object sender, MouseEventArgs e) {
//e.Button == MouseButtons.Right
}
private void ChildFrm_Load(object sender, EventArgs e)
{
}
}
}
父窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
ChildFrm frm = new ChildFrm();
//订阅事件
frm.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
frm.ShowDialog();
}
void frm_ChangeTextEvent(string text) {
this.textBox1.Text = text;
}
}
}
就这样