目录
参考:
一、简介
1.1、提出问题
1.2、问题分析
1.3、拓展Socket的同步连接与异步连接
1.3.1、什么是同步连接、异步连接
二、Socket同步通信实现
2.1、Server
2.2、Client
三、Socket异步通信实现
参考:https://www.debugease.com/csharp/1114414.html
一、简介 1.1、提出问题服务端明明监听到一个服务端,但是却没有连接成功,如下所示:
服务端的监听源码:
using KeenRay.Common;using KeenRay.Common.SocketCommu;using Prism.Commands;using Prism.Events;using Prism.Mvvm;using Prism.Regions;using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Drawing;using System.IO;using System.Linq;using System.Linq.Expressions;using System.Net;using System.Net.Sockets;using System.Runtime.InteropServices;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Windows;using System.Windows.Forms;using System.Windows.Threading;using System.Xml.Linq;namespace KeenRay.SocketCommu{ public class SocketCommuInit : BindableBase { #region 属性集 //服务端 public Socket Client { get; set; } public int _receiveFlagValue = 0; /// /// 接收标志值 /// public int ReceiveFlagValue { get { return _receiveFlagValue; } set { SetProperty(ref _receiveFlagValue, value); } } #endregion #region 字段集 SocketCommuReceive socketCommuReceive = new SocketCommuReceive(); //服务器 Socket Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //监听多个Client Dictionary clientList = new Dictionary(); //IP string strSocketIP = null; //端口号 int point = 40000; #endregion #region 方法集 #region 单例 private volatile static SocketCommuInit _instance = null; private static readonly object lockobj = new object(); /// /// 创建实例 /// /// public static SocketCommuInit CreateInstance() { if (_instance == null) { lock (lockobj) { if (_instance == null) { _instance = new SocketCommuInit(); } } } return _instance; } #endregion #region IP配置 /// /// IP、端口配置 /// public void IPandPortConfig() { try { string strSocketConfigFilePath; strSocketConfigFilePath = Environment.CurrentDirectory + "\Config" + "\SocketAndBullHeadConfig.xml"; XDocument SocketDocument = XDocument.Load(strSocketConfigFilePath); XElement SocketRoot = SocketDocument.Root; //Socket节点 XElement SocketPoint = SocketRoot.Element("Socket"); //IP XElement SocketIP = SocketPoint.Element("SocketIP"); strSocketIP = SocketIP.Value; //端口 XElement SocketPort = SocketPoint.Element("SocketPort"); point = Convert.ToInt32(SocketPort.Value); } catch(Exception ex) { LogHelper.Error("SocketClass.cs::IPandPortConfig() IP/端口配置发生错误:--------------" + ex.ToString()); } } #endregion #region 启动Socket /// /// 启动 /// public void StartFlag() { //启动Socket string strSocketStartFlag = null; string strSocketConfigFilePath; strSocketConfigFilePath = Environment.CurrentDirectory + "\Config" + "\SocketAndBullHeadConfig.xml"; XDocument SocketDocument = XDocument.Load(strSocketConfigFilePath); XElement SocketRoot = SocketDocument.Root; //Socket节点 XElement SocketPoint = SocketRoot.Element("Socket"); //启动Socket XElement SocketStart = SocketPoint.Element("SocketStart"); strSocketStartFlag = SocketStart.Value; if (strSocketStartFlag == "1") { IPAddress IP = IPAddress.Parse(strSocketIP); IPEndPoint iPEndPoint = new IPEndPoint(IP, point); Server.Bind(iPEndPoint); Server.Listen(10); //开启线程监听 Thread th = new Thread(ListenFunc); th.IsBackground = true; th.Start(Server); } } #endregion #region 监听 /// /// 监听 /// /// public void ListenFunc(object Server) { while (true) { try { //客户端 Client = ((Socket)Server).Accept(); //clientList.Add(Client.RemoteEndPoint.ToString(), Client); //可以监听多个Client Thread threadServer = new Thread(new ParameterizedThreadStart(socketCommuReceive.Receive)); threadServer.IsBackground = true; threadServer.Start(Client); } catch (Exception ex) { LogHelper.Error("SocketClass.cs::Listen()监听发错了错误:--------------" + ex.ToString()); } } } #endregion #endregion }}客户端的连接源码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using Microsoft.Win32;using System.IO;using System.Net;using System.Net.Sockets;using System.Threading;using System.Windows.Threading;using KeenRayLargePC.Views;using System.Windows.Interop;using System.Xml.Linq;using System.Drawing.Imaging;using System.Drawing;using KeenRayLargePC.Common;using KeenRayLargePC.Config;using System.ComponentModel;using System.Windows.Forms.Integration;using AxKrayImgViewLib;using KeenRayLargePC.DicomOperate;using Prism.Commands;using KeenRayLargePC.PadDataAcessLayer;using KeenRayLargePC.PadDbContent;using System.Linq.Expressions;using KeenRayLargePC.Server;namespace KeenRayLargePC{ public partial class MainWindow : Window,INotifyPropertyChanged { #region 命令集 /// /// 窗宽改变命令 /// public DelegateCommand SliderWWValueChangedCommand { get; private set; } /// /// 窗位改变命令 /// public DelegateCommand SliderWLValueChangedCommand { get; private set; } #endregion #region 属性集 BitmapImage bmpImage = null; public BitmapImage BmpImage { get { return bmpImage; } set { bmpImage = value; RaiseChanged("VideoImage"); } } public event PropertyChangedEventHandler PropertyChanged; public void RaiseChanged(string property) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(property)); } } private int _winWidth = 1; /// /// 窗宽 /// public int WinWidth { get { return _winWidth; } set { _winWidth = value; if (PropertyChanged != null) { //RaisePropertyChanged("PopupEraserMoreIsOpen"); PropertyChanged(this, new PropertyChangedEventArgs("WinWidth")); } } } private int _winLevel = 1; /// /// 窗位 /// public int WinLevel { get { return _winLevel; } set { _winLevel = value; if (PropertyChanged != null) { //RaisePropertyChanged("PopupEraserMoreIsOpen"); PropertyChanged(this, new PropertyChangedEventArgs("WinLevel")); } } } private bool _popupEraserMoreIsOpen; /// /// 清除菜单是否打开 /// public bool PopupEraserMoreIsOpen { get { return _popupEraserMoreIsOpen; } set { _popupEraserMoreIsOpen = value; if (PropertyChanged != null) { //RaisePropertyChanged("PopupEraserMoreIsOpen"); PropertyChanged(this, new PropertyChangedEventArgs("PopupEraserMoreIsOpen")); } } } #endregion #region 标志集 /*页面标志*/ const int HOMEPAGE_FLAG = 1; const int STUDYPAGE_FLAG = 2; const int REVIEWPAGE_FLAG = 3; /*曝光参数标志*/ const int KV_PLUS_FLAG = 11; const int KV_REDUCE_FLAG = 12; const int MA_PLUS_FLAG = 13; const int MA_REDUCE_FLAG = 14; const int MS_PLUS_FLAG = 15; const int MS_REDUCE_FLAG = 16; const int MAS_PLUS_FLAG = 17; const int MAS_REDUCE_FLAG = 18; const int MAS_MODE_FLAG = 19; const int MAMS_MODE_FLAG = 20; const int FOCUS_FLAG = 21; const int START_EXPOSE_FLAG = 22;//启动曝光按钮 const int SAVE_EXPOSE_VALUE = 23;//保存曝光参数 /*导航状态标志*/ const int OPEN_VIDEO_FLAG = 31;//打开视频监控 const int CLOSE_VIDEO_FLAG = 32;//关闭视屏监控 const int PANEL_TEMP_FLAG = 33; //平板温度 const int HEAT_CAPACITY_FLAG = 34;//热容量 const int BATTERY_CAPACITY_FLAG = 35;//电池容量 const int EXPOSE_STATUS_FLAG = 36;//曝光状态。接收到的内容(int),0:就绪。1:预备。2:曝光。3:禁止。 /*其他信息标志*/ const int DICOM_FLAG = 41; //Dicom const int USER_INFO_FLAG = 42; //用户信息 /*状态标志*/ bool blStartFlag = false; //Socket启动标志 bool imageEditFlag = false; //图像编辑标识 bool blCameraRecStatue = false; //视频监控开关状态。false:关闭。true:打开。 bool blImageRecStatue = false; bool blCommonRecStatue = false; //其他状态开关标志 const string strCameraRecStatue = "CameraRecStatue"; const string strImageRecStatue = "ImageRecStatue"; const string strCommonRecStatue = "CommonRecStatue"; bool blUpdateTimeFlag = true; //是否运行实时更新时间 bool blCanAnalysisPackageHead = true; //是否允许解析包头 bool blCanAnalysisPackageContent = true; //是否允许解析包内容 #endregion #region 属性集 #region 图像显示控件属性 public bool m_bEditFlag = false; //编辑标志 public int m_nGrabAcqStatus; //0-DR 1-RF 2-SPOT public int nWindowLevel; //窗位 public int nWindowWidth; //窗宽 public KrayDicomLib.DicomFile m_cDicomFile; ImgViewHandle handle = new ImgViewHandle(); #endregion #region 包属性:用来解析包,实现被动接收,如接收Dicom,用户信息 byte[] bytPageType = new byte[4]; //页面类型 byte[] bytRecFlag = new byte[4]; //标志位字节 byte[] bytContentLong = new byte[4]; //长度字节 byte[] bytContent = new byte[0]; //内容 int iPageFlag = -1; //页面类型 int iRecFlag = -1; //接收标志 int iContentLong = -1; //包内容长度 int iPathLong = -1; //Dicom图路径长度 const int FLAG_LENGTH = 12; //包头长度 #endregion #region Dicom图操作 PatientInfoDal patientInfoDal = new PatientInfoDal(); SeriesInfoDal seriesInfoDal = new SeriesInfoDal(); ImagesInfoDal imagesInfoDal = new ImagesInfoDal(); List patientInfoList = new List(); List seriesInfoList = new List(); List imagesInfoList = new List(); #endregion #region 视频监控属性 List VideoList = new List(); //存放视频帧 const int BITMAP_IMAGE_LENGTH = 921654; //帧字节长度 byte[] btCurrentBitmapImage = new byte[BITMAP_IMAGE_LENGTH];//当前帧 byte[] btLastBitmapImage = new byte[BITMAP_IMAGE_LENGTH]; //上一帧 #endregion #region Socket通用属性 List bufferList = new List(); //缓存队列 byte[] btRecBuffer = new byte[16* 1000 * 1000];//socket接收缓存区 int Port = 50000;//端口号 IPAddress IP = IPAddress.Parse("127.0.0.1"); IpConfig ipConfig = new IpConfig(); IPEndPoint serverIPEndPoint = null; public Socket Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Log log = Log.CreateInstance();//日志类 iPadReceive ipadReceive = iPadReceive.CreateInstance(); iPadSend ipadSend = iPadSend.CreateInstance(); InitPacs initPacs = InitPacs.CreateInstance();//启动Pacs初始配置。 SendModality sendModality = SendModality.CreateInstance(); #endregion #endregion #region 方法集 #region 单例 //public volatile static MainWindow _instance = null; //public static readonly object lockobj = new object(); / / 创建实例 / / //public static MainWindow CreateInstance() //{ // if (_instance == null) // { // lock (lockobj) // { // if (_instance == null) // { // _instance = this; // } // } // } // return _instance; //} #endregion /// /// 默认构造函数 /// public MainWindow() { //InitializeComponent(); log.ClearLogFunc();//清除日志 ipadReceive.setMainWindowDeleaget(this); ipadSend.setMainWindowDeleaget(this); //更新UI: 可以用 App.Current.Dispatcher.Invoke((Action)delegate () { this.DataContext = this; }); //窗宽改变命令初始化 SliderWWValueChangedCommand = new DelegateCommand(SliderWWValueChangedFun); //窗位改变命令初始化 SliderWLValueChangedCommand = new DelegateCommand(SliderWLValueChangedFun); m_nGrabAcqStatus = 0; nWindowWidth = 65535; nWindowLevel = 32768; //获取配置文件默认的IP、Port ipConfig.IpConfigFunc(ref blStartFlag, ref IP, ref Port); StartFunc();//默认就启动Socket连接PC /* 线程更新时间 */ Thread UpdateTimeThread = new Thread(UpdateTime); UpdateTimeThread.IsBackground = true; UpdateTimeThread.Start(); } /// /// 启动 /// private void StartFunc() { try { if (blStartFlag == true) { serverIPEndPoint = new IPEndPoint(IP, Port); //获得要连接的远程服务器应用程序的IP地址和端口号 Client.Connect(serverIPEndPoint); if (Client.Connected == true) { log.WriteDebugLogFunc("MainWindow.xaml.cs::StartFunc()——" + "已连接服务器" + " "); MessageBox.Show("连接服务器状态:成功"); /*开线程接收*/ Thread threadReceive = new Thread(ipadReceive.Receive); threadReceive.IsBackground = true; threadReceive.Start(Client); /*开线程发送归档状态信息*/ Thread thSendModality = new Thread(sendModality.SendImageArchiveFunc2); thSendModality.IsBackground = true; thSendModality.Start(); } else { log.WriteDebugLogFunc("MainWindow.xaml.cs::StartFunc()——" + "服务器已经开启,但无法连接服务器" + " "); } } } catch (Exception ex) { //MessageBox.Show("服务器未开启或客户端输入的IP不正确"); log.WriteErrorLogFunc("MainWindow.xaml.cs::StartFunc()——" + "服务器未开启或客户端输入的IP不正确:" + ex.ToString() + " "); } } /// /// 导图:iPads导图到Pacs /// /// /// private void btn_SendPacs_Click(object sender, RoutedEventArgs e) { try { Pacs pacsDialog = new Pacs(); pacsDialog.SetValidServerList(); pacsDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; pacsDialog.ShowDialog(); } catch (Exception ex) { log.WriteErrorLogFunc("MainWindow.xaml.cs::btn_Image_Click()——" + "视频监控开关状态发送错误:" + ex.ToString() + " "); } } /// /// 关闭系统 /// /// /// private void BtnSysShutDown_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } /// /// 系统配置,弹窗window窗口 /// /// /// private void btnSystemConfig_Click(object sender, RoutedEventArgs e) { try { if (Client != null && Client.Connected == true) { MessageBox.Show("Pad已经连上PC,无需配置IP/Port了"); return; } SystemConfigWindow systemConfigWindow = new SystemConfigWindow(); systemConfigWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; if (systemConfigWindow.ShowDialog() == true) { IP = IPAddress.Parse(systemConfigWindow.IP); Port = systemConfigWindow.Port; blStartFlag = true;//若是IP配置正确,则启动Socket连接 } StartFunc();//启动Socket连接 } catch(Exception ex) { log.WriteErrorLogFunc("MainWindow.xaml.cs::btnSystemConfig_Click()——" + "IP格式或端口不正确:" + ex.ToString() + " "); } } #region 更新时间 /// /// 更新时间 /// private void UpdateTime() { while (blUpdateTimeFlag == true) { Thread.Sleep(1000); //更新UI: 可以用 App.Current.Dispatcher.Invoke((Action)delegate () { this.lblDateTime_Second.Content = DateTime.Now.ToLongTimeString().ToString(); this.lblDateTime_day.Content = DateTime.Now.ToString("yyyy-MM-dd"); }); } } #endregion #region 发送视频监控 /// /// 视频监控开关状态 /// /// /// private void Camera_Click(object sender, RoutedEventArgs e) { try { if (blCameraRecStatue == false)//如果在关闭状态下,那就打开它。 { //视频打开,其他功能必须关闭 ModuleRunFlagFunc(strCameraRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, OPEN_VIDEO_FLAG, null); } else if (blCameraRecStatue == true)// 如果在打开状态下,那就关闭它。 { blCameraRecStatue = false; ipadSend.SendPackageFunc(STUDYPAGE_FLAG, CLOSE_VIDEO_FLAG, null); //关闭视频监控下,必须清空Image的画面 App.Current.Dispatcher.Invoke((Action)delegate () { imgDisPlay.Source = null; }); } } catch (Exception ex) { log.WriteErrorLogFunc("MainWindow.xaml.cs::Camera_Click()——" + "视频监控开关状态发送错误:" + ex.ToString() + " "); } } #endregion #region 发送曝光标志 /// /// 启动曝光 /// /// /// private void btnExpose_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, START_EXPOSE_FLAG, null); } private void btn_KvPlus_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, KV_PLUS_FLAG, null); } private void btn_KvReduce_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, KV_REDUCE_FLAG, null); } private void btn_mAPlus_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MA_PLUS_FLAG, null); } private void btn_mAReduce_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MA_REDUCE_FLAG, null); } private void btn_msPlus_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MS_PLUS_FLAG, null); } private void btn_msReduce_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MS_REDUCE_FLAG, null); } private void btn_mAsPlus_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MAS_PLUS_FLAG, null); } private void btn_mAsReduce_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MAS_REDUCE_FLAG, null); } private void btn_mAsMode_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MAS_MODE_FLAG, null); } private void btn_mAmsMode_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, MAMS_MODE_FLAG, null); } /// /// 焦点 /// /// /// private void btn_Focus_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, FOCUS_FLAG, null); } private void btn_SaveExposeValues_Click(object sender, RoutedEventArgs e) { //其他功能必须关闭 ModuleRunFlagFunc(strCommonRecStatue); ipadSend.SendPackageFunc(STUDYPAGE_FLAG, SAVE_EXPOSE_VALUE, null); } #endregion /// /// 模块运行标志 /// /// public void ModuleRunFlagFunc(string str) { switch (str) { case strCameraRecStatue: blCameraRecStatue = true; blImageRecStatue = false; blCommonRecStatue = false; break; case strImageRecStatue: blCameraRecStatue = false; blImageRecStatue = true; blCommonRecStatue = false; //同时需要发一个信息给主程序,关闭视频监控,不让它发信息过来了。 ipadSend.SendPackageFunc(STUDYPAGE_FLAG, CLOSE_VIDEO_FLAG, null); //并且让当前的image清零 App.Current.Dispatcher.Invoke((Action)delegate () { this.imgDisPlay.Source = null; }); break; case strCommonRecStatue: //同时需要发一个信息给主程序,关闭视频监控,不让它发信息过来了。 ipadSend.SendPackageFunc(STUDYPAGE_FLAG, CLOSE_VIDEO_FLAG, null); //并且让当前的image清零 App.Current.Dispatcher.Invoke((Action)delegate () { this.imgDisPlay.Source = null; }); blCameraRecStatue = false; blImageRecStatue = false; blCommonRecStatue = true; break; default: break; } } #region Dicom图 /// /// 点击加载一张Dicom图:主要用来测试 /// /// /// private void OpenDicom_Click(object sender, RoutedEventArgs e) { try { /*直接打开*/ //System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog(); //open.Filter = "DCM图像文件|*.dcm"; //open.RestoreDirectory = false; //if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) //{ // handle.PutImage(this.imageview, open.FileName, ref m_cDicomFile); //} 适应窗口 //imageview.FtsImage(); //this.imageview.Invalidate(); 隐藏视频监控窗口 //this.imgDisPlay.Visibility = Visibility.Hidden; //this.host.Visibility = Visibility.Visible; /*调用ShowDicom打开*/ System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog(); open.Filter = "DCM图像文件|*.dcm"; open.RestoreDirectory = false; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ipadReceive.ShowDicom(open.FileName); } } catch (Exception ex) { log.WriteErrorLogFunc("MainWindow.xaml.cs::OpenDicom_Click()——" + "打开dicom图发生错误:" + ex.ToString() + " "); } } /// /// 左旋转 /// /// /// private void btn_LeftRotate_Click(object sender, RoutedEventArgs e) { this.imageview.LeftRotate(); this.imageview.Invalidate(); } /// /// 右旋转 /// /// /// private void btn_RightRotate_Click(object sender, RoutedEventArgs e) { this.imageview.RightRotate(); this.imageview.Invalidate(); } /// /// 下侧翻 /// /// /// private void btn_DownFlip_Click(object sender, RoutedEventArgs e) { this.imageview.FlipVertical(); this.imageview.Invalidate(); } /// /// 右侧翻 /// /// /// private void btn_RightFlip_Click(object sender, RoutedEventArgs e) { this.imageview.FlipHorizon(); this.imageview.Invalidate(); } /// /// 等比显示:显示一张图 /// /// /// private void btn_ShowOneImage_Click(object sender, RoutedEventArgs e) { if (this.imageview.HasImage) { this.imageview.RealSizeImage(); this.imageview.Invalidate(); } } /// /// 全屏显示 /// /// /// private void btn_FullScreen_Click(object sender, RoutedEventArgs e) { //适应窗口 imageview.FtsImage(); imageview.Invalidate(); } /// /// 手抓移动 /// /// /// private void btn_AllowMove_Click(object sender, RoutedEventArgs e) { if (this.imageview.HasImage) { this.imageview.ProcType = KrayImgViewLib.tagPROC_TYPE.PT_MOVE; } } /// /// 禁止移动 /// /// /// private void btn_ForbiddenMove_Click(object sender, RoutedEventArgs e) { if (this.imageview.HasImage) { this.imageview.ProcType = KrayImgViewLib.tagPROC_TYPE.PT_NONE; this.imageview.Invalidate(); } } /// /// 右标记 /// /// /// private void btnR_Click(object sender, RoutedEventArgs e) { //string sFontName = configInfoModel.RLMarkFontName; //int nFontSize = configInfoModel.RLMarkFontSize; string sFontName = "微软雅黑"; int nFontSize = 200; if (this.imageview.HasImage) { this.imageview.DrawFlag = "R"; this.imageview.AddText(200, 30, "R", nFontSize, sFontName); this.imageview.ProcType = KrayImgViewLib.tagPROC_TYPE.PT_NONE; this.imageview.Invalidate(); SetEditFlag(true); } } /// /// 设置编辑标志值 /// /// public void SetEditFlag(bool state) { imageEditFlag = state; } /// /// 左标识命令功能函数 /// private void btnL_Click(object sender, RoutedEventArgs e) { //string sFontName = configInfoModel.RLMarkFontName; //int nFontSize = configInfoModel.RLMarkFontSize; string sFontName = "微软雅黑"; int nFontSize = 200; if (this.imageview.HasImage) { int X2 = this.imageview.Width - 200; int Y2 = 30; this.imageview.DrawFlag = "L"; this.imageview.AddText(X2, Y2, "L", nFontSize, sFontName); this.imageview.ProcType = KrayImgViewLib.tagPROC_TYPE.PT_NONE; this.imageview.Invalidate(); SetEditFlag(true); } } /// /// 文字标识命令功能函数 /// private void btnText_Click(object sender, RoutedEventArgs e) { string sFontName = "微软雅黑"; int nFontSize = 80; if (this.imageview.HasImage) { this.imageview.SetTextFont(sFontName, nFontSize); this.imageview.ProcType = KrayImgViewLib.tagPROC_TYPE.PT_TEXT; SetEditFlag(true); } } /// /// 清除