Windows窗体模拟时钟集成到Web部件Moss 2007
我有一个windows窗体模拟时钟,我需要创建一个web部件(moss 2007) 我的代码Windows窗体模拟时钟集成到Web部件Moss 2007,windows,forms,sharepoint-2007,web-parts,Windows,Forms,Sharepoint 2007,Web Parts,我有一个windows窗体模拟时钟,我需要创建一个web部件(moss 2007) 我的代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security; using System.Web; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Web;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Reflection;
using System.Drawing;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
namespace ClockWebPart
{
public class ClockWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
Form form = new Form();
/// Constructor
public ClockWebPart()
{
InitializeComponent();
}
/// Initialization here
private void ClockDesign_Load(object sender, EventArgs e)
{
try
{
// read the embeded resource
Assembly asmImage = Assembly.GetExecutingAssembly();
Stream streamImage = asmImage.GetManifestResourceStream("ClockWebPart.clock.bmp");
Bitmap bmpBackground = new Bitmap(streamImage);
SetFormBackgroundImage(bmpBackground);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Resource wasn't found!");
}
}
/// <summary>
/// Set the form background
/// </summary>
/// <param name="bmpImage"></param>
private void SetFormBackgroundImage(Bitmap bmpImage)
{
Color clrPixel = bmpImage.GetPixel(0, 0);
bmpImage.MakeTransparent(clrPixel);
form.BackgroundImage = bmpImage;
// Set the form size from image size
form.Size = bmpImage.Size;
}
/// Override the paint event
//protected override void OnLoad(EventArgs e)
//{
// base.OnLoad(e);
//}
protected void OnPreRender(System.Windows.Forms.PaintEventArgs e)
{
// Set the origin to center of the form
e.Graphics.TranslateTransform(80.0F, 80.0F);
// Save translated graphics state; So origin will remain at center of form when restore
GraphicsState transState = e.Graphics.Save();
// Capture a copy of current time for consistent
DateTime dtNow = DateTime.Now;
// rotation starts from new center of the form
e.Graphics.RotateTransform(dtNow.Second * 6.0F - 90.0F);
// Anti-alias only affect the next shape
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
// draw the second hand at new center of the form
e.Graphics.FillRectangle(new SolidBrush(Color.Silver), -1, -1, 55, 2);
//// Restore graphics state to translated state and fill second hand
e.Graphics.Restore(transState);
// minus 90 degree because start at x-axis
e.Graphics.RotateTransform(dtNow.Minute * 6.0F - 90.0F);
// Anti-alias only affect the next shape
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillRectangle(new SolidBrush(Color.Silver), -1, -1, 45, 3);
//// Restore graphics state to translated state and fill minute hand
//gHands.Restore(transState);
// Reset transformation matrix to identity and fill rectangle.
e.Graphics.ResetTransform();
// Set the origin to center of the form
e.Graphics.TranslateTransform(80.0F, 80.0F);
// minus 90 degree because start at x-axis; Minute affects hour hand too
e.Graphics.RotateTransform(dtNow.Hour * 30.0F - 90.0F + dtNow.Minute * 0.5F);
// Anti-alias only affect the next shape
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillRectangle(new SolidBrush(Color.Silver), -1, -1, 35, 4);
}
/// Force the form to repaint for every tick
private void tmrRotate_Tick(object sender, EventArgs e)
{
// Force to redraw
//this.Invalidate();
form.Refresh();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
#region Windows Form 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.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ClockWebPart));
this.niMainMenu = new System.Windows.Forms.NotifyIcon(this.components);
this.cmsAllMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tsmiAbout = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiSeparator = new System.Windows.Forms.ToolStripSeparator();
this.tsmiExit = new System.Windows.Forms.ToolStripMenuItem();
this.tmrRotate = new System.Windows.Forms.Timer(this.components);
this.cmsAllMenu.SuspendLayout();
form.SuspendLayout();
//
// niMainMenu
//
this.niMainMenu.ContextMenuStrip = this.cmsAllMenu;
this.niMainMenu.Icon = ((System.Drawing.Icon)(resources.GetObject("niMainMenu.Icon")));
this.niMainMenu.Text = "Time flies!";
this.niMainMenu.Visible = true;
//
// cmsAllMenu
//
this.cmsAllMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmiAbout,
this.tsmiSeparator,
this.tsmiExit});
this.cmsAllMenu.Name = "cmsAllMenu";
this.cmsAllMenu.Size = new System.Drawing.Size(108, 54);
//
// tsmiAbout
//
this.tsmiAbout.Name = "tsmiAbout";
this.tsmiAbout.Size = new System.Drawing.Size(107, 22);
this.tsmiAbout.Text = "About";
//this.tsmiAbout.Click += new System.EventHandler(this.tsmiAbout_Click);
//
// tsmiSeparator
//
this.tsmiSeparator.Name = "tsmiSeparator";
this.tsmiSeparator.Size = new System.Drawing.Size(104, 6);
//
// tsmiExit
//
this.tsmiExit.Name = "tsmiExit";
this.tsmiExit.Size = new System.Drawing.Size(107, 22);
this.tsmiExit.Text = "Exit";
//this.tsmiExit.Click += new System.EventHandler(this.tsmiExit_Click);
//
// tmrRotate
//
this.tmrRotate.Enabled = true;
this.tmrRotate.Interval = 1000;
this.tmrRotate.Tick += new System.EventHandler(this.tmrRotate_Tick);
//
// frmIrregular
//
form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
form.ClientSize = new System.Drawing.Size(160, 160);
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
form.Name = "frmIrregular";
form.ShowInTaskbar = false;
form.Text = "Time flies";
form.TransparencyKey = System.Drawing.SystemColors.Control;
form.Load += new System.EventHandler(this.ClockDesign_Load);
//this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmIrregular_MouseDown);
//this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmIrregular_MouseMove);
this.cmsAllMenu.ResumeLayout(false);
form.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.NotifyIcon niMainMenu;
private System.Windows.Forms.ContextMenuStrip cmsAllMenu;
private System.Windows.Forms.ToolStripMenuItem tsmiAbout;
private System.Windows.Forms.ToolStripMenuItem tsmiExit;
private System.Windows.Forms.ToolStripSeparator tsmiSeparator;
private System.Windows.Forms.Timer tmrRotate;
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统安全;
使用System.Web;
使用System.Windows.Forms;
使用System.Drawing.Drawing2D;
使用System.IO;
运用系统反思;
使用系统图;
使用Microsoft.SharePoint;
使用Microsoft.SharePoint.WebPartPage;
命名空间时钟Web部件
{
公共类ClockWebPart:Microsoft.SharePoint.WebPartPages.WebPart
{
表单=新表单();
///建造师
公共时钟Web部件()
{
初始化组件();
}
///这里初始化
私有void ClockDesign_加载(对象发送器、事件参数e)
{
尝试
{
//读取嵌入的资源
Assembly asmImage=Assembly.getExecutionGassembly();
streamImage=asmImage.GetManifestResourceStream(“ClockWebPart.clock.bmp”);
位图bmpBackground=新位图(streamImage);
SetFormBackgroundImage(bmpBackground);
}
捕获(例外情况除外)
{
Show(例如,Message,“未找到资源!”);
}
}
///
///设置窗体背景
///
///
私有void SetFormBackgroundImage(位图bmp图像)
{
Color clrPixel=bmpImage.GetPixel(0,0);
bmpImage.MakeTransparent(CLR像素);
form.BackgroundImage=bmp图像;
//从图像大小设置窗体大小
form.Size=bmpImage.Size;
}
///覆盖绘制事件
//受保护的覆盖无效加载(事件参数e)
//{
//基础荷载(e);
//}
受保护的void OnPreRender(System.Windows.Forms.PaintEventArgs e)
{
//将原点设置为窗体的中心
e、 图形.可译转换(80.0F,80.0F);
//保存转换后的图形状态;以便在还原时原点将保持在窗体的中心
GraphicsState transState=e.Graphics.Save();
//捕获当前时间的副本以实现一致性
DateTime dtNow=DateTime.Now;
//旋转从形状的新中心开始
e、 图形.旋转变换(dtNow.Second*6.0F-90.0F);
//反别名仅影响下一个形状
e、 Graphics.SmoothingMode=SmoothingMode.AntiAlias;
//在表格的新中心画第二只手
e、 图形.FillRectangle(新的SolidBrush(颜色为银色),-1,-1,55,2);
////将图形状态恢复为转换状态并填充二手
e、 图形恢复(transState);
//负90度,因为从x轴开始
e、 图形.旋转变换(dtNow.Minute*6.0F-90.0F);
//反别名仅影响下一个形状
e、 Graphics.SmoothingMode=SmoothingMode.AntiAlias;
e、 图形。圆角矩形(新的SolidBrush(颜色为银色),-1,-1,45,3);
////将图形状态恢复为转换状态并填充分针
//恢复(跨州);
//将变换矩阵重置为恒等式并填充矩形。
e、 Graphics.ResetTransform();
//将原点设置为窗体的中心
e、 图形.可译转换(80.0F,80.0F);
//负90度,因为从x轴开始;分钟也影响时针
e、 图形.旋转变换(dtNow.Hour*30.0F-90.0F+dtNow.Minute*0.5F);
//反别名仅影响下一个形状
e、 Graphics.SmoothingMode=SmoothingMode.AntiAlias;
e、 图形.圆角矩形(新的SolidBrush(颜色.银色),-1,-1,35,4);
}
///强制窗体为每个勾号重新绘制
私有void tmrRotate_Tick(对象发送方,事件参数e)
{
//强制重画
//这个。使无效();
form.Refresh();
}
///
///必需的设计器变量。
///
private System.ComponentModel.IContainer components=null;
///
///清理所有正在使用的资源。
///
///如果应释放托管资源,则为true;否则为false。
#区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
私有void InitializeComponent()
{
this.components=new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager资源=新的System.ComponentModel.ComponentResourceManager(typeof(ClockWebPart));
this.niMainMenu=new System.Windows.Forms.NotifyIcon(this.components);
this.cmsAllMenu=new System.Windows.Forms.ContextMenuStrip(this.components);
this.tsmiAbout=new System.Windows.Forms.ToolStripMenuItem();
this.tsmiSeparator=new System.Windows.Forms.ToolStripSeparator();
this.tsmiExit=new System.Windows.Forms.ToolStripMenuItem();
this.tmrRotate=new System.Windows.Forms.Timer(this.components);
这个.cmsAllMenu.SuspendLayout();
form.SuspendLayout();
//
//尼曼菜单
//
this.niMainMenu.ContextMenuStrip=this.cmsAllMenu;
this.niMainMenu.Icon=((System.Drawing.Icon)(resources.GetObject(“niMainMenu.Icon”));
this.niMainMenu.Text=“时光飞逝!”;
this.niMainMenu.Visible=true;
//
//cmsAllMenu
//
this.cmsAllMenu.Items.AddRange(新的System.Windows.Forms.ToolStripItem[]{
这是关于,
这是一个空分器,
using System.Linq;