自定义一个函数指针为什么会错的?~~~~~~~ 散分~~~~~~

asam2183 2003-06-02 09:51:08
我在一个自定义控件定义一个事件:
public event Submit
但没有在控件里实现这个方法,而是在调用该控件的页面写
运行没问题,只是Warning, 但编译成msi就说有制命错
请问有什么解求方法
...全文
98 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
asam2183 2003-06-19
  • 打赏
  • 举报
回复
谢谢Knight94(愚翁)
各位兄弟辛苦啦
问题还没解决,最近没时间去搞这个了,
迟点再弄了
yuwen16 2003-06-17
  • 打赏
  • 举报
回复
在C#中应该没有叫指针的概念吧。。
呵呵。。虽然类似,,
关于委托的,看msdn。。有详细说明,绝对可以解决你的问题。
zhanguan 2003-06-17
  • 打赏
  • 举报
回复
接分
gaosamuel 2003-06-17
  • 打赏
  • 举报
回复
程序是痛苦的。
tyjoe 2003-06-17
  • 打赏
  • 举报
回复
UP
Knight94 2003-06-17
  • 打赏
  • 举报
回复
以下是一个控件的源码(参考一下吧):
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace WinFormDemo
{
public class ListBoxTextChangingEventArgs : CancelEventArgs
{
private string newText;
public ListBoxTextChangingEventArgs(string newText)
{
this.newText = newText;
}
public string NewText
{
get{return this.newText;}
}
}
public delegate void ListBoxTextChangingEventHandler(object sender, ListBoxTextChangingEventArgs e);
/// <summary>
/// Summary description for EditableList.
/// </summary>
public class EditableList : System.Windows.Forms.UserControl
{
public event EventHandler ButtonClick;
public event ListBoxTextChangingEventHandler ItemChanging;
protected System.Windows.Forms.ListBox listBox;
protected System.Windows.Forms.TextBox textBox;
protected System.Windows.Forms.Button button;
protected bool ignoreNextMouseUp = true;
protected bool editing = false;
private static int EditorStripHeight = 20;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public EditableList()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitForm call

}

public ListBox ListBox
{
get{return this.listBox;}
}
public TextBox TextBox
{
get{return this.textBox;}
}
public Button Button
{
get{return this.button;}
}
public bool Editing
{
get{return this.editing;}
set
{
if(this.editing != value)
{
if(!value)
this.EndEditing(value);
else
this.StartEditing();
}
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listBox = new System.Windows.Forms.ListBox();
this.textBox = new System.Windows.Forms.TextBox();
this.button = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listBox
//
this.listBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox.Name = "listBox";
this.listBox.Size = new System.Drawing.Size(150, 147);
this.listBox.TabIndex = 0;
this.listBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ListBox_MouseUp);
this.listBox.SelectedIndexChanged += new System.EventHandler(this.ListBox_SelectedIndexChanged);
//
// textBox
//
this.textBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox.Location = new System.Drawing.Point(8, 120);
this.textBox.Name = "textBox";
this.textBox.TabIndex = 2;
this.textBox.Text = "";
this.textBox.Visible = false;
this.textBox.Size = new Size(100, EditorStripHeight);
this.textBox.LostFocus += new System.EventHandler(this.TextBox_LostFocus);
//
// button
//
this.button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button.Location = new System.Drawing.Point(112, 120);
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(30, EditorStripHeight);
this.button.TabIndex = 2;
this.button.Text = "...";
this.button.Visible = false;
this.button.Click += new System.EventHandler(this.Button_Click);
this.button.LostFocus += new System.EventHandler(this.Button_LostFocus);
//
// EditableList
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button,
this.textBox,
this.listBox});
this.Name = "EditableList";
this.ResumeLayout(false);

}
#endregion
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(Control.FromHandle(msg.HWnd) == this.textBox)
{
if(keyData == Keys.Enter)
{
this.EndEditing(true);
return true;
}
else if(keyData == Keys.Escape)
{
this.EndEditing(false);
return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void ListBox_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.ignoreNextMouseUp)
{
this.ignoreNextMouseUp = false;
return;
}

if(this.listBox.IndexFromPoint(e.X, e.Y) == this.listBox.SelectedIndex)
{
this.StartEditing();
}
}

protected virtual void StartEditing()
{
if(this.listBox.SelectedIndex != -1)
{
Rectangle rect = this.listBox.GetItemRectangle(this.listBox.SelectedIndex);
rect = this.listBox.RectangleToScreen(rect);
rect = this.listBox.Parent.RectangleToClient(rect);

if(rect.Height < 20)
{
rect.Y -= (20 - rect.Height)/2;
if(rect.Y < 0)
rect.Y = this.ClientRectangle.Top;
}

rect.Width -= this.button.Width;

this.textBox.Modified = false;
this.textBox.Bounds = rect;
this.textBox.Visible = true;
this.textBox.Text = this.listBox.SelectedItem.ToString();
this.textBox.Focus();
this.textBox.SelectionStart = 0;
this.textBox.SelectionLength = 0;

this.button.Visible = true;
this.button.Location = new Point(this.textBox.Right, this.textBox.Top);
this.editing = true;
}
}

protected virtual void EndEditing(bool save)
{
if(!this.Editing)
return;

if(save && this.textBox.Modified)
{
ListBoxTextChangingEventArgs e = new ListBoxTextChangingEventArgs(this.textBox.Text);
this.OnItemChanging(e);
if(!e.Cancel)
this.listBox.Items[this.listBox.SelectedIndex] = this.textBox.Text;
}

this.editing = false;
this.textBox.Text = String.Empty;
this.textBox.Visible = false;
this.button.Visible = false;
}

private void TextBox_LostFocus(object sender, System.EventArgs e)
{
if(!this.button.Focused)
this.EndEditing(true);
}

private void Button_LostFocus(object sender, EventArgs e)
{
if(!this.textBox.Focused)
this.EndEditing(true);
}

private void ListBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(Control.MouseButtons == MouseButtons.Left)
this.ignoreNextMouseUp = true;
}

private void Button_Click(object sender, System.EventArgs e)
{
this.OnButtonClick(EventArgs.Empty);
}
protected virtual void OnItemChanging(ListBoxTextChangingEventArgs e)
{
try
{
if(this.ItemChanging != null)
this.ItemChanging(this, e);
}
catch{}
}
protected virtual void OnButtonClick(EventArgs e)
{
try
{
if(this.ButtonClick != null)
{
this.ButtonClick(this, e);
}
}
catch{}
}
}
}
sunny6281 2003-06-16
  • 打赏
  • 举报
回复
是不是不安全代码问题?
majh5235 2003-06-13
  • 打赏
  • 举报
回复
我也想知道delegate如何与event联系
asam2183 2003-06-13
  • 打赏
  • 举报
回复
我的是这样定义的:
public event tempEventHandler.SubmitEventHandler Submit;
其中tempEventHandler是一个类来的:

to:Knight94(愚翁)
如果是你那种定义,得怎么改?,好象我改到你那样的还有Warning
Knight94 2003-06-10
  • 打赏
  • 举报
回复
是否定义了相关的delege,即类似如下的代码:
public delegate void sbmitEventHandler(object sender, EventArgs e);
ggdw 2003-06-10
  • 打赏
  • 举报
回复
接分
asam2183 2003-06-03
  • 打赏
  • 举报
回复
up
asam2183 2003-06-02
  • 打赏
  • 举报
回复
to:fupip(小贝)
我有加啦
public event temp.sbmitEventHandler Submit;
JJ77 2003-06-02
  • 打赏
  • 举报
回复
u's code?
shuker 2003-06-02
  • 打赏
  • 举报
回复
致命错是什么?
可以贴出来看看吗
贝贝壳壳 2003-06-02
  • 打赏
  • 举报
回复
public 和Event之间加上委托的名称。

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧