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

  • SEARCH
  • Home
  • 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 3681434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:41:18+00:00 2026-05-19T03:41:18+00:00

I give up now on this very simple test I’ve been trying to run.

  • 0

I give up now on this very simple test I’ve been trying to run. I want to add a subview to my window which does nothing but draw a line from one corner of the iPhone’s screen to the other and then, using touchesMoved() it is supposed to draw a line from the last to the current point.
The issues:
1. Already the initial line is not visible.
2. When using Interface Builder, the initial line is visible, but drawRect() is never called, even if I call SetNeedsDisplay().

It can’t be that hard…can somebody fix the code below to make it work?

In main.cs in FinishedLaunching():

oView = new TestView();
oView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
oView.Frame = new System.Drawing.RectangleF(0, 0, 320, 480);
window.AddSubview(oView);
window.MakeKeyAndVisible ();

The TestView.cs:

using System;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.Foundation;
namespace Test
{
    public class TestView : UIView
    {
        public TestView () : base()
        {
        }

        public override void DrawRect (RectangleF area, UIViewPrintFormatter formatter)
        {
            CGContext oContext = UIGraphics.GetCurrentContext();
            oContext.SetStrokeColor(UIColor.Red.CGColor.Components);
            oContext.SetLineWidth(3.0f);
            this.oLastPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oLastPoint.Y;
            this.oCurrentPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oCurrentPoint.Y;
            oContext.StrokeLineSegments(new PointF[] {this.oLastPoint, this.oCurrentPoint });
            oContext.Flush();
            oContext.RestoreState();
            Console.Out.WriteLine("Current X: {0}, Y: {1}", oCurrentPoint.X.ToString(), oCurrentPoint.Y.ToString());
            Console.Out.WriteLine("Last X: {0}, Y: {1}", oLastPoint.X.ToString(), oLastPoint.Y.ToString());

        }

        private PointF oCurrentPoint = new PointF(0, 0);
        private PointF oLastPoint = new PointF(320, 480);

        public override void TouchesMoved (MonoTouch.Foundation.NSSet touches, UIEvent evt)
        {
            base.TouchesMoved (touches, evt);
            UITouch oTouch = (UITouch)touches.AnyObject;
            this.oCurrentPoint = oTouch.LocationInView(this);
            this.oLastPoint = oTouch.PreviousLocationInView(this);
            this.SetNeedsDisplay();
        }
    }
}
  • 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-19T03:41:19+00:00Added an answer on May 19, 2026 at 3:41 am

    You overrode the wrong Draw method.

    You overrode DrawRect (RectangleF, UIViewPrintFormatter) which is used for printing.

    You want to override Draw (RectangleF)

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

Sidebar

Related Questions

Okay. Now I give up. I have been playing with this for hours. I
I have been struggling with something which in theory should be very simple for
I have a problem with this very simple block of code. please give me
I try to solve this problem several times and give up. Now, when I
Right now I have double numba = 5212.6312 String.Format({0:C}, Convert.ToInt32(numba) ) This will give
Give a base class Base , I want to write a method Test, like
I will give very simple example. class Implementation: IMyInterface { string mArg; public Implementation(string
Really having an issue debugging this...the reason why is probably very simple but I'm
Now this is going to be a very absurd question. But what can I
I have a simple 'Buy Now' Google Checkout button on my Django site (very

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.