找回密码
 立即注册

QQ登录

只需一步,快速开始

mindrayguowei

中级会员

122

主题

274

帖子

986

积分

中级会员

积分
986

活字格认证

QQ
mindrayguowei
中级会员   /  发表于:2016-4-20 11:42  /   查看:3083  /  回复:1
本帖最后由 mindrayguowei 于 2016-4-20 11:51 编辑

为了通过HypertextLink来实现点击一下HypertextLink内容来实现下拉修改HypertextLink的值的功能, 添加了一个TextFieldClicked事件, 点击以下会弹出一个combobox, 通过combobox来选择相应的值, 并设置到HypertextLink里去, 但是遇到很严重的程序崩溃问题, 部署到客户的电脑上后,频繁的出现偶发的系统崩溃, 异常无法捕捉到. 但是在开发环境里面无法重现该问题.

以下是代码
  1. void _textControl_TextFieldClicked(object sender, TextFieldEventArgs e)
  2.         {
  3.             if (_textControl.EditMode == TXTextControl.EditMode.ReadOnly)
  4.             {
  5.                 return;
  6.             }

  7.             try
  8.             {
  9.                 HypertextLink textLink = e.TextField as HypertextLink;
  10.               
  11.                 if (textLink != null)
  12.                 {
  13.                     string[] strArray = textLink.Target.Split(";".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
  14.                     if (strArray.Length == 1)
  15.                     {
  16.                         _textControl.Select(textLink.Start - 1, textLink.Length);
  17.                         return;
  18.                     }
  19.                     //if (Array.IndexOf(strArray, textLink.Text) == -1)
  20.                     //{
  21.                     //    _textControl.Select(textLink.Start - 1, textLink.Length);
  22.                     //    return;
  23.                     //}

  24.                     _textControl.Controls.Clear();
  25.                     ComboBox comboBox = new ComboBox();
  26.                     comboBox.Items.AddRange(strArray);

  27.                     int left = (textLink.Bounds.Location.X - _textControl.ScrollLocation.X) / TwipsPerPixel * _textControl.ZoomFactor / 100;
  28.                     int top = (textLink.Bounds.Location.Y - _textControl.ScrollLocation.Y) / TwipsPerPixel * _textControl.ZoomFactor / 100;

  29.                     System.Drawing.Point cbLocation = new System.Drawing.Point(left, top);
  30.                     comboBox.Location = cbLocation;
  31.                     comboBox.DropDownStyle = ComboBoxStyle.Simple;
  32.                     comboBox.BackColor = System.Drawing.Color.FromArgb(255, 255, 192);

  33.                     string maxString = string.Empty;
  34.                     Array.ForEach<string>(strArray, delegate(string str) { if (str.Trim().Length > maxString.Length) maxString = str; });

  35.                     System.Drawing.Graphics graphics = _textControl.CreateGraphics();
  36.                     System.Drawing.SizeF sizef = graphics.MeasureString(maxString, _textControl.Font);
  37.                     comboBox.Width = (int)Math.Ceiling(sizef.Width) + 30;

  38.                     comboBox.SelectedText = textLink.Text;
  39.                     _textControl.Controls.Add(comboBox);
  40.                     comboBox.Focus();

  41.                     _currentTextlink = textLink;

  42.                     comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
  43.                     comboBox.LostFocus += new EventHandler(comboBox_LostFocus);
  44.                 }
  45.             }
  46.             catch (Exception ex)
  47.             {
  48.                 LogAdapter.LogError("_textControl_TextFieldClicked:" + ex.Message);
  49.             }
  50.         }

  51. void comboBox_LostFocus(object sender, EventArgs e)
  52.         {
  53.             try
  54.             {
  55.                 if (_currentTextlink == null) return;

  56.                 ComboBox combobox = sender as ComboBox;
  57.                 if (combobox.SelectedItem == null)
  58.                 {
  59.                     _currentTextlink.Text = ((ComboBox)sender).Text;
  60.                 }
  61.                 else
  62.                 {
  63.                     _currentTextlink.Text = ((ComboBox)sender).SelectedItem.ToString();
  64.                 }
  65.                 _documentDirty = true;
  66.             }
  67.             catch (Exception ex)
  68.             {
  69.                 LogAdapter.LogError("comboBox_LostFocus:" + ex.Message);
  70.             }
  71.             finally
  72.             {
  73.                 try
  74.                 {
  75.                     _currentTextlink = null;
  76.                     _textControl.Controls.Clear();
  77.                 }
  78.                 catch
  79.                 { }
  80.             }
  81.         }

  82.         void comboBox_SelectedIndexChanged(object sender, EventArgs e)
  83.         {
  84.             try
  85.             {
  86.                 if (_currentTextlink == null) return;

  87.                 ComboBox combobox = sender as ComboBox;
  88.                 if (combobox.SelectedItem == null)
  89.                 {
  90.                     _currentTextlink.Text = ((ComboBox)sender).Text;
  91.                 }
  92.                 else
  93.                 {
  94.                     _currentTextlink.Text = ((ComboBox)sender).SelectedItem.ToString();
  95.                 }
  96.                 _documentDirty = true;
  97.             }
  98.             catch (Exception ex)
  99.             {
  100.                 LogAdapter.LogError("comboBox_SelectedIndexChanged:" + ex.Message);
  101.             }
  102.             finally
  103.             {
  104.                 try
  105.                 {
  106.                     _currentTextlink = null;
  107.                     _textControl.Controls.Clear();
  108.                 }
  109.                 catch
  110.                 { }
  111.             }
  112.         }
复制代码


以下是输出的dump文件在windbg里面的信息, 生产环境是windows 8.1 x64, 在某些windows 7 64位和32位下也都会报错,编译环境是32位程序, 没有拿到symbol文件, 调试不下去了

Loading unloaded module list
.....
eax=00000000 ebx=00000000 ecx=00000000 edx=00000000 esi=00000003 edi=00000003
eip=773fc7ec esp=00d0d3b8 ebp=00d0d540 iopl=0         nv up ei pl nz na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200206
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll -
ntdll!NtWaitForMultipleObjects+0xc:
773fc7ec c21400          ret     14h


1 个回复

倒序浏览
gw0506
超级版主   /  发表于:2016-4-20 15:25:13
沙发
开发环境不能重现的话确实很麻烦。
崩溃的时候没有任何提示信息是吗?我看你代码里加了很多try catch。如果还没有出现信息。我判断不是应用层面的了,也不是.NET Framework层面了。

从错误信息看,与ntdll.dll有关。我建议你找个Win7环境,装上开发环境然后再试试。不行的话,用Win7编译,然后给客户部署尝试。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部