我有两个类,一个是 Arc 类,一个是 Line 类
public class Arc
{
protected double startx;
protected double starty;
protected double endx;
protected double endy;
protected double radius;
public Arc(){}
}
public class Line
{
protected double startx;
protected double starty;
protected double endx;
protected double endy;
protected double length;
public Line(){}
}
Run Code Online (Sandbox Code Playgroud)
但我想将弧和线存储在同一个列表中,所以我尝试了这样的界面
public interface Entity
{
double StartX();
double StratY();
double EndX();
double EndY();
}
Run Code Online (Sandbox Code Playgroud)
然后,我向每个类添加了适当的方法,并添加了使用该接口的代码。现在我可以将两种类型的对象添加到列表中,但我想从线对象获取长度,并且不想向弧或界面添加长度方法。我是将线条对象转换回这样的线条对象的唯一选择吗?
List<Entity> entities = new List<Entity>();
entities.Add(new Line(10,10,5,5));
Line myLine = (Line)Entities[0]
double length = myLine.Length();
Run Code Online (Sandbox Code Playgroud)
*假设我在线路类中拥有所有正确的方法。 …
我有一些代码启动一个进程并挂钩一个事件处理程序来处理进程退出时,我的代码是用C#编写的,我想知道Delphi是否可以实现类似的东西.
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "notepad.exe";
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new System.EventHandler(Process_OnExit);
myProcess.Start();
public void Process_OnExit(object sender, EventArgs e)
{
//Do something when the process ends
}
Run Code Online (Sandbox Code Playgroud)
我对Delphi了解不多,所以任何帮助都会受到赞赏,谢谢.
using System;
using System.Threading;
public delegate void LoadingProgressCallback(double PercentComplete,string ItemName);
public delegate void LoadCompleteCallback(int ItemID, string ItemName);
public static class Program
{
public static void Main(string[] args)
{
LoadTest loadTest = new LoadTest();
loadTest.LoadItems(args);
}
}
public class LoadTest
{
ManualResetEvent resetEvent;
int numThreads = 0;
public LoadTest()
{}
public void LoadItems(string[] Items)
{
numThreads = 0;
resetEvent = new ManualResetEvent(false);
foreach(string item in Items)
{
Console.WriteLine("Adding {0} to ThreadPool",item);
ThreadPool.QueueUserWorkItem
(
delegate
{
Load(item, this.progCall, this.compCall);
}
); …Run Code Online (Sandbox Code Playgroud) 我有这个代码(好吧,类似的东西).
private delegate void GenericCallback<T>(T Info);
private void DoWork()
{
System.Threading.Thread Worker = new System.Threading.Thread(
delegate()
{
TestMethod(TestMethodCallback<string>);
}
);
Worker.Start();
}
private void TestMethod(GenericCallback<string> Callback)
{
System.Threading.Thread.Sleep(1000);
if(Callback != null)
{
Callback("Complete");
}
}
private void TestMethod(GenericCallback<int> Callback)
{
System.Threading.Thread.Sleep(1000);
if(Callback != null)
{
Callback(25);
}
}
private void TestMethodCallback<T>(T Info)
{
MessageBox.Show(Info.ToString());
}
Run Code Online (Sandbox Code Playgroud)
这允许我TestMethod根据参数的类型调用不同的版本,同时也允许我有一个回调方法.
这是一种不好的形式,还是一种公认的做法?
在我的管道中,我有一个阶段可以检查特定计算机(节点)是否离线。如果是的话,我想跳过下一阶段。但是,下一阶段设置为使用离线代理,因此似乎无法检查 When 子句。
这是我的管道的简化版本:
pipeline {
agent none
environment {
CONTINUERUN = true
}
stages {
stage('Check Should Run') {
agent any
steps {
script {
CONTINUERUN = false
}
}
}
stage('Skip this stage') {
agent {
label 'offlineAgent'
}
when {
expression {
CONTINUERUN
}
}
steps {
//Do stuff here
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,构建只是挂在“跳过此阶段”阶段。我假设,因为代理离线。当已知代理离线时,如何跳过此阶段?
我最近开始玩C#,但我发现它非常令人沮丧.似乎每次我想添加我认为是一个简单的控件,我最终要么在网上搜索,要么自己编写.我只是觉得我花了更多的时间来重新创建控件以使它们按照应有的方式工作,而实际创建应用程序的时间则更少.
例如: 在另一个问题中,我问是否可以删除组合框上的边框; 我认为应该在控件中构建一些东西,但是我必须为这个简单的改动建立自己的控件.
我对C#/ .net来说太新了,还是我只是期待太多?我知道我喜欢C#所以不要因为这样的感觉而咬我的头,只是帮助我理解我所缺少的东西,以及我是否应该继续学习和使用C#.
我正在编写一个简单的应用程序,我想用notifyIcon而不是表单来控制,我已经通过Google找到了示例,但我的notifyIcon将不会出现.我究竟做错了什么?
static class MainEntryClass
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
C2F TestApp = new C2F();
Application.Run();
TestApp.Dispose();
}
}
class C2F
{
public C2F()
{
InitializeComponent();
loadSettings();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(C2F));
this.niC2F = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.separatorToolStripMenuItem = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
//
// niC2F
//
this.niC2F.BalloonTipText = …Run Code Online (Sandbox Code Playgroud) 在启动新应用程序时,有哪些方法可以确定您需要哪些对象,应该做什么以及它们应该如何相互交互?
这是白板的工作,还是只是根据需要开始编码和移动东西更容易?
我有一个使用SmtpClient发送电子邮件的应用程序,但在应用程序关闭之前不会发送电子邮件.我搜索并搜索以找到问题的解决方案,但我找不到.
系统确实安装了Symantec防病毒软件,这可能是问题所在.
有没有人能解决这个问题?
这是我正在使用的代码.
public class EMail
{
private string server;
public string Server {get{return this.server;}set{this.server = value;}}
private string to;
public string To {get{return this.to;}set{this.to = value;}}
private string from;
public string From {get{return this.from;}set{this.from = value;}}
private string subject;
public string Subject {get{return this.subject;}set{this.subject = value;}}
private string body;
public string Body {get{return this.body;}set{this.body = value;}}
public EMail()
{}
public EMail(string _server, string _to, string _from, string _subject, string _body)
{
this.Server = _server;
this.To = _to;
this.From …Run Code Online (Sandbox Code Playgroud) 有没有办法让SplitContainer只调整panel1的大小?我有一个Vertical SplitContainer,当我移动分割器时,我希望第一个面板的大小增加/减少,而不是改变第二个面板的大小,我希望表单增加和减小尺寸.
我创建了一些代码来增加/减少窗体的大小,但是Panel2也在改变大小,因此整个面板并不总是可见的.
我是否必须制作自己的容器,或者是否可以使用SplitContainer?
我有一个表单"MainWin",其中包含一个Panel"MainPanel"MainPanel包含SplitContainer"MainSplitContainer".Panel1包含TreeView,Panel2包含3个面板,这些面板根据TreeView中选择的项目可见.我希望这三个面板始终完全可见(我打算限制分割器的扩展,以便表单不能扩展到屏幕之外),这是可能的还是我应该创建自己的控件并调整使用的大小MouseDown,MouseUp和MouseMove事件?
c# ×7
.net ×1
callback ×1
delphi ×1
email ×1
generics ×1
interface ×1
jenkins ×1
notifyicon ×1
object ×1
oop ×1
smtpclient ×1
threadpool ×1
winforms ×1