Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4087016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:48:06+00:00 2026-05-20T18:48:06+00:00

I have a windows form analog clock and I need to create a web

  • 0

I have a windows form analog clock and I need to create a web part (moss 2007).

my code

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;



    }
}

It’s give error

Web Part Error: An error has occurred.

what is problem ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:48:07+00:00Added an answer on May 20, 2026 at 6:48 pm

    There can be many reasons for this error.

    using System.Linq;
    

    is defenitely not supported in MOS 2007. Remove this line and test.

    Also disable custom errors in web.config to display full error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form which has to be refreshed automatically without using any
I have a windows form which has 1 button (for simplicity). On clicking this
I have a windows form with a label (or another control, i'm open to
I have a Windows Form application that, when the form is Activated, Deactivated, or
I have a windows form application. I have a query which return me datetime
I believe the proper term is recursively . I have a Windows Form, and
i have a windows app in vb.net , i am trying to read a
I am working in Visual Studio 2008 and have a Windows Forms project +
Hi i have stepped into some problem related to timer. hope somebody can help..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.