{"id":21176840,"url":"https://github.com/joelumbley/time","last_synced_at":"2025-06-11T12:07:01.321Z","repository":{"id":262762483,"uuid":"888269067","full_name":"JoeLumbley/Time","owner":"JoeLumbley","description":"A simple Windows application that displays the current local time. The application utilizes optimized rendering techniques to ensure smooth updates and an aesthetically pleasing user interface.","archived":false,"fork":false,"pushed_at":"2024-11-20T02:24:37.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T11:32:55.890Z","etag":null,"topics":["bufferedgraphics","graphics","real-time","time-display","vb-net","windows-forms"],"latest_commit_sha":null,"homepage":"","language":"Visual Basic .NET","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JoeLumbley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-14T05:19:33.000Z","updated_at":"2024-11-20T02:24:41.000Z","dependencies_parsed_at":"2024-11-14T12:31:11.674Z","dependency_job_id":null,"html_url":"https://github.com/JoeLumbley/Time","commit_stats":null,"previous_names":["joelumbley/time"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FTime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FTime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FTime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoeLumbley%2FTime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoeLumbley","download_url":"https://codeload.github.com/JoeLumbley/Time/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243624093,"owners_count":20321029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bufferedgraphics","graphics","real-time","time-display","vb-net","windows-forms"],"created_at":"2024-11-20T17:12:24.180Z","updated_at":"2025-03-14T18:24:27.773Z","avatar_url":"https://github.com/JoeLumbley.png","language":"Visual Basic .NET","readme":"# Time🕒\n\nA simple Windows application that displays the current local time. \n\nThe application utilizes optimized rendering techniques to ensure smooth updates and an aesthetically pleasing user interface.\n\n\n![001](https://github.com/user-attachments/assets/92e3e427-61f7-4924-bf7e-c364bb192af0)\n\n\nFeatures\n\n- Real-time display of the current time.\n\n- Responsive design that adjusts font size and position based on the window size.\n\n- Utilizes buffered graphics for improved performance and visual quality.\n\n\n\n\n---\n\n\n### Code Walkthrough\n\n#### 1. **Class Declaration**\n```vb\nPublic Class Form1\n```\nThis line defines a new class named `Form1`. In Windows Forms applications, a class represents a window or form.\n\n#### 2. **Variable Declarations**\n```vb\nPrivate Context As BufferedGraphicsContext\nPrivate Buffer As BufferedGraphics\nPrivate DisplayText As String\nPrivate DisplayFont As New Font(\"Segoe UI\", 12, FontStyle.Regular)\nPrivate DisplayFontSize As Single\nPrivate DisplayPosition As New Point(100, 0)\n```\n- **Context**: Manages the buffered graphics.\n- **Buffer**: Holds the graphics that will be drawn to the screen.\n- **DisplayText**: Stores the current time as a string.\n- **DisplayFont**: Defines the font used to display the time.\n- **DisplayFontSize**: Stores the size of the font, which will change based on the window size.\n- **DisplayPosition**: Determines where the time will be drawn on the form.\n\n#### 3. **Form Load Event**\n```vb\nPrivate Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load\n    InitializeForm()\n    InitializeBuffer()\n    Timer1.Interval = 20\n    Timer1.Enabled = True\n    Debug.Print($\"Program running... {Now.ToShortTimeString()}\")\nEnd Sub\n```\n- This method runs when the form loads.\n- **InitializeForm()**: Sets up the form's appearance and properties.\n- **InitializeBuffer()**: Prepares the graphics buffer.\n- **Timer1.Interval = 20**: Sets the timer to tick every 20 milliseconds.\n- **Timer1.Enabled = True**: Starts the timer, which triggers the `Timer1_Tick` event.\n- **Debug.Print**: Outputs a message to the debug console.\n\n#### 4. **Timer Tick Event**\n```vb\nPrivate Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick\n    DisplayText = Now.ToShortTimeString()\n    Refresh() ' Calls OnPaint Sub\nEnd Sub\n```\n- This method runs every time the timer ticks.\n- **DisplayText**: Updates to the current time.\n- **Refresh()**: Triggers the form to redraw itself, calling the `OnPaint` method.\n\n#### 5. **Form Resize Event**\n```vb\nPrivate Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize\n    DisplayFontSize = ClientRectangle.Width \\ 12\n    DisplayFont = New Font(\"Segoe UI\", DisplayFontSize, FontStyle.Regular)\n    DisplayPosition.X = ClientRectangle.Width \\ 2\n    DisplayPosition.Y = ClientRectangle.Height \\ 2\n\n    If Buffer IsNot Nothing Then Buffer.Dispose()\n    Buffer = Nothing\nEnd Sub\n```\n- This method runs when the form is resized.\n- **DisplayFontSize**: Adjusts the font size based on the form's width.\n- **DisplayPosition**: Centers the time display in the form.\n- **Buffer.Dispose()**: Cleans up the existing buffer to prepare for a new one.\n\n#### 6. **OnPaint Method**\n```vb\nProtected Overrides Sub OnPaint(ByVal e As PaintEventArgs)\n    If Buffer Is Nothing Then Buffer = Context.Allocate(e.Graphics, ClientRectangle)\n    DrawFrame()\n    Buffer.Render(e.Graphics)\nEnd Sub\n```\n- This method is called when the form needs to be redrawn.\n- **Buffer Allocation**: Allocates graphics if it hasn't been done yet.\n- **DrawFrame()**: Calls a method to draw the current time.\n- **Buffer.Render**: Draws the buffer content to the screen.\n\n#### 7. **DrawFrame Method**\n```vb\nPrivate Sub DrawFrame()\n    If Buffer IsNot Nothing Then\n        Try\n            With Buffer.Graphics\n                .CompositingMode = Drawing2D.CompositingMode.SourceOver\n                .TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias\n                .SmoothingMode = Drawing2D.SmoothingMode.HighQuality\n                .PixelOffsetMode = Drawing2D.PixelOffsetMode.None\n                .CompositingQuality = Drawing2D.CompositingQuality.HighQuality\n                .Clear(Color.Black)\n                .DrawString(DisplayText, DisplayFont, Brushes.White, DisplayPosition, AlineCenterMiddle)\n            End With\n        Catch ex As Exception\n            Debug.Print(\"Draw error: \" \u0026 ex.Message)\n        End Try\n    Else\n        Debug.Print(\"Buffer is not initialized.\")\n    End If\nEnd Sub\n```\n- This method draws the current time onto the buffer.\n- **Graphics Settings**: Sets various drawing quality settings.\n- **Clear(Color.Black)**: Clears the buffer with a black background.\n- **DrawString**: Draws the time string in white at the specified position.\n- **Error Handling**: Catches any errors during drawing and prints them to the debug console.\n\n#### 8. **InitializeForm Method**\n```vb\nPrivate Sub InitializeForm()\n    CenterToScreen()\n    SetStyle(ControlStyles.UserPaint, True)\n    SetStyle(ControlStyles.OptimizedDoubleBuffer, True)\n    SetStyle(ControlStyles.AllPaintingInWmPaint, True)\n    Text = \"Time🕒 - Code with Joe\"\n    Me.WindowState = FormWindowState.Maximized\nEnd Sub\n```\n- This method sets up the form's initial properties.\n- **CenterToScreen()**: Centers the form on the screen.\n- **SetStyle**: Configures the form to use double buffering for smoother rendering.\n- **Text**: Sets the title of the window.\n- **WindowState**: Maximizes the form when it opens.\n\n#### 9. **InitializeBuffer Method**\n```vb\nPrivate Sub InitializeBuffer()\n    Context = BufferedGraphicsManager.Current\n    Context.MaximumBuffer = Screen.PrimaryScreen.WorkingArea.Size\n    Buffer = Context.Allocate(CreateGraphics(), ClientRectangle)\nEnd Sub\n```\n- This method initializes the graphics buffer.\n- **BufferedGraphicsManager.Current**: Gets the current graphics manager.\n- **MaximumBuffer**: Sets the maximum buffer size.\n- **Allocate**: Allocates the buffer for drawing.\n\n\nThis application uses Windows Forms to create a simple clock that updates every 20 milliseconds. It utilizes buffered graphics for smooth rendering and adjusts the display based on the size of the window.\n\n\n\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoelumbley%2Ftime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoelumbley%2Ftime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoelumbley%2Ftime/lists"}