C\#사용자 정의 이벤트 시 뮬 레이 션 바람 풀 흔 들 림 효과
5500 단어 c#사용자 정의 이벤트
Hover TreeForm 에 잔디 를 그 렸 는데 그 위 에 많은 풀(시 뮬 레이 션)이 있 습 니 다.
HewenqiTianyi 류 는 날 씨 를 모 의 하면'바람'사건(HoverTreeWindEvent)을 일 으 키 고 바람 이 동풍 이나 서풍 이 있 거나 정지 된다.
동풍 이 불면 풀이 서쪽 으로 넘 어 지고 서풍 이 불면 동쪽 으로 간다.멈 추 면 풀이 이리 저리 쓰 러 지지 않 는 다.
잔디 위의 모든 풀 은 HoverTreeWindEvent 사건 을 감청 하고 풍향(WindD direction)에 따라 자 세 를 조절 한다.
HewenqiTianyi 에는 일정 시간 마다 풍향 을 조정 하 는 이벤트 가 발생 하 는 타이머 가 있 습 니 다.
감 청 된'바람'사건 은 WinForm 의 스 레 드 가 아니 기 때문에 WinForm 의'풀'자 세 를 바 꿔 야 합 니 다.
BeginInvoke 방법 과 의뢰 를 사용 하여 WinForm 스 레 드 밖에서 컨트롤 에 접근 합 니 다.구체 적 으로 Hover TreeGrass 사용자 컨트롤 을 보십시오.
효과 그림:
HewenqiTianyi 클래스 코드:
using System;
using System.Timers;
namespace TianYiHeWenQi
{
class HewenqiTianyi
{
public static event ActionEventHandler HoverTreeWindEvent;
WindEventArgs _arg = new WindEventArgs();
public HewenqiTianyi()
{
Timer h_timer = new Timer();
h_timer.Interval = 3000;
h_timer.Elapsed += H_timer_Elapsed;
h_timer.Start();
}
Random _HoverClock=new Random ();
private void H_timer_Elapsed(object sender, ElapsedEventArgs e)
{
_arg.WindType = (WindDdirection)(_HoverClock.Next(3));
OnAction(_arg);
}
protected void OnAction(WindEventArgs ev)
{
HoverTreeWindEvent?.Invoke(ev);
//
//if (HoverTreeWindEvent != null)
//{
// HoverTreeWindEvent(ev);
//}
}
}
class WindEventArgs : EventArgs
{
public WindDdirection WindType { get; set; }
}
enum WindDdirection
{
East,
West,
Static
}
delegate void ActionEventHandler(WindEventArgs ev);
}
사용자 정의 컨트롤 코드:
using System;
using System.Windows.Forms;
namespace TianYiHeWenQi
{
public partial class HoverTreeGrass : UserControl
{
delegate void MySetText(string text);
public HoverTreeGrass()
{
InitializeComponent();
HewenqiTianyi.HoverTreeWindEvent += HewenqiTianyi_HoverTreeWindEvent;
}
private void UpdateLabel(WindDdirection wd)
{
if (label_grass.InvokeRequired)
{
// InvokeRequired ,
Action<WindDdirection> actionDelegate = (x) => {
switch (x)
{
case WindDdirection.East:
label_grass.Location = new System.Drawing.Point(40 - 9, label_grass.Location.Y);
label_grass.Text="\\";
break;
case WindDdirection.West:
label_grass.Location = new System.Drawing.Point(40+9, label_grass.Location.Y);
label_grass.Text = "/";
break;
case WindDdirection.Static:
label_grass.Location = new System.Drawing.Point(40, label_grass.Location.Y);
label_grass.Text = "|";
break;
}
};
//
// Action<string> actionDelegate = delegate(string txt) { this.label_grass.Text = txt; };
this.label_grass.BeginInvoke(actionDelegate, wd);
}
else
{
switch (wd)
{
case WindDdirection.East:
label_grass.Text = "\\";
break;
case WindDdirection.West:
label_grass.Text = "/";
break;
case WindDdirection.Static:
label_grass.Text = "|";
break;
}
}
}
private void HewenqiTianyi_HoverTreeWindEvent(WindEventArgs ev)
{
UpdateLabel(ev.WindType);
}
}
}
HoverTreeForm 창 코드:
using System.Windows.Forms;
namespace TianYiHeWenQi
{
public partial class HoverTreeForm : Form
{
public HoverTreeForm()
{
InitializeComponent();
for (int i = 0; i < tableLayoutPanel_hovertree.ColumnCount; i++) {
for (int j = 0; j < tableLayoutPanel_hovertree.RowCount; j++) {
tableLayoutPanel_hovertree.Controls.Add(new HoverTreeGrass(), i, j);
}
}
HewenqiTianyi h_ty = new HewenqiTianyi();
}
}
}
원본 다운로드:http://xiazai.jb51.net/201707/yuanma/TianYiHeWenQi.rar총결산
위 에서 말 한 것 은 편집장 님 께 서 소개 해 주신 C\#사용자 정의 이벤트 시 뮬 레이 션 바람 풀 흔 들 림 효과 입 니 다.도움 이 되 셨 으 면 좋 겠 습 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C#Task를 사용하여 비동기식 작업을 수행하는 방법라인이 완성된 후에 이 라인을 다시 시작할 수 없습니다.반대로 조인(Join)만 결합할 수 있습니다 (프로세스가 현재 라인을 막습니다). 임무는 조합할 수 있는 것이다. 연장을 사용하여 그것들을 한데 연결시키는 것이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.