2008-11-20 14 views
5

मैं अभिव्यक्ति मिश्रण, ट्वर्ल, या एडोब लाइटरूम के हिस्से के रूप में भेजे गए जैसे काले कस्टम विंडो (सीमा और नियंत्रण के साथ) बनाने में सक्षम होना चाहता हूं।विनफॉर्म - मैं एक कस्टम विंडोज सीमा कैसे बना सकता हूं और बटन को बंद/छोटा कर सकता हूं?

क्या कोई मालिक खींची गई विंडो बनाने का कोई सर्वोत्तम तरीका है?

प्लेटफार्म: सी # और WindowsForms (कोई भी संस्करण)

+0

केवल पैनलों का उपयोग करके कस्टम विंडोज फॉर्म बनाने के लिए आलेख है - [पैनलों का उपयोग कर सी # में कस्टम विंडोज फॉर्म बनाना] (http://www.codeproject.com/Articles/1068043/Creating- कस्टम-विंडोज़- फोरम-in -Csharp-use-pane) –

+0

[WinForms ऐप में कस्टम टाइटलबार/क्रोम का संभावित डुप्लिकेट] (http://stackoverflow.com/questions/42460/custom-titlebars-chrome-in-a-winforms-app) –

उत्तर

4

कस्टम क्रोम उपकरण देखो और अनुभव है कि आप चाहते हैं, के साथ आप प्रदान नहीं करते हैं तो बात इस तरह का आसान है सी # में खुद को करने के लिए। असल में, आप एक सीमा रहित रूप (फॉर्मबॉर्डर स्टाइल = कोई नहीं) बनाते हैं और उसके बाद नियंत्रणों को रखकर सभी नियंत्रण और सीमाएं बनाते हैं, जहां आपको उनकी आवश्यकता होती है (शीर्षक पट्टी के लिए एक लेबल, बंद करने और कम करने के लिए कमांड बटन) और/या ड्राइंग ग्राफिक्स ऑब्जेक्ट का उपयोग कर सीधे फॉर्म की सतह पर।

आपको इसे "नकली" शीर्षक पट्टी के चारों ओर खींचने की अनुमति देने के लिए कोड को भी लागू करना होगा (इसे देखने के नमूने के लिए this answer देखें)। आपको अपने स्वयं के आकार बदलने की व्यवस्था भी लागू करनी पड़ सकती है (यदि आपको फॉर्म बदलने योग्य होने की आवश्यकता है)।

अंत में, हालांकि कस्टम-फॉर्म कोड थोड़ा सा हो सकता है, आप इसे एक ही रूप में कार्यान्वित कर सकते हैं और उसके बाद आपके आवेदन में अन्य सभी रूप इस फॉर्म से प्राप्त होते हैं, जो इसे कस्टम के लिए एक बहुत ही उपयोगी तकनीक बनाता है एक पूरा आवेदन खरीदना।

+0

ईमानदारी से एक बहुत ही उचित दृष्टिकोण –

2

मेरा काम ऐप की निष्क्रिय विंडो, दूसरों की तुलना में सक्रिय विंडो को अधिक ध्यान देने योग्य, चमकदार बनाना था। ऐप में कई खुली खिड़कियां हैं, कुछ मोडल, कुछ मॉडलस - और एमडीआई माता-पिता एक।

आप ग्राहक क्षेत्र के अंदर एक फ्रेम - सीमा के समान कुछ उपयोग कर सकते हैं। यहाँ कोड का टुकड़ा, एक आधार वर्ग का एक हिस्सा (सीधे एक रूप में इस्तेमाल किया जा सकता है): वर्ग के

#region Кастомизированное поведение - рамки, активность и т.д. 
    private bool isCurrentlyActive = false; 
    private bool childControlsAreHandled = false; 
    private Pen activeWindowFramePen, inactiveWindowFramePen; 
    private Point[] framePoints; 

    private void AddControlPaintHandler(Control ctrl) 
    { 
     ctrl.Paint += DrawWindowFrame; 
     if (ctrl.Controls != null) 
     { 
      foreach (Control childControl in ctrl.Controls) 
      { 
       AddControlPaintHandler(childControl); 
      } 
     } 
    } 

    protected override void OnActivated(EventArgs e) 
    { 
     base.OnActivated(e); 
     if ((this.childControlsAreHandled == false) 
      && (WindowFrameType != Forms.WindowFrameType.NoFrame) 
      && (this.MdiParent == null)) 
     { 
      RecalculateWindowFramePoints(); 
      AddControlPaintHandler(this); 
      this.childControlsAreHandled = true; 
     } 

     this.isCurrentlyActive = true; 
     if (InactiveWindowOpacity < 1) 
     { 
      base.Opacity = 1; 
     } 
     base.Invalidate(true); 
    } 

    protected override void OnDeactivate(EventArgs e) 
    { 
     base.OnDeactivate(e); 
     this.isCurrentlyActive = false; 
     if (InactiveWindowOpacity < 1) 
     { 
      base.Opacity = InactiveWindowOpacity; 
     } 
     base.Invalidate(true); 
    } 

    protected override void OnResizeEnd(EventArgs e) 
    { 
     base.OnResizeEnd(e); 
     this.framePoints = null; 
     RecalculateWindowFramePoints(); 
     this.Invalidate(true); 
    } 

    private Pen ActivePen 
    { 
     get 
     { 
      if (this.isCurrentlyActive) 
      { 
       if (this.activeWindowFramePen == null) 
       { 
        this.activeWindowFramePen = new Pen(Color.FromArgb((int)(WindowFrameOpacity*255), WindowFrameActiveColor), WindowFrameSize * 2); 
       } 
       return this.activeWindowFramePen; 
      } 
      else 
      { 
       if (this.inactiveWindowFramePen == null) 
       { 
        this.inactiveWindowFramePen = new Pen(Color.FromArgb((int)(WindowFrameOpacity*255), WindowFrameInactiveColor), WindowFrameSize * 2); 
       } 
       return this.inactiveWindowFramePen; 
      } 
     } 
    } 

    private Point[] RecalculateWindowFramePoints() 
    { 
     if ((WindowFrameType == Forms.WindowFrameType.AllSides) 
      && (this.framePoints != null) 
      && (this.framePoints.Length != 5)) 
     { 
      this.framePoints = null; 
     } 
     if ((WindowFrameType == Forms.WindowFrameType.LeftLine) 
      && (this.framePoints != null) 
      && (this.framePoints.Length != 2)) 
     { 
      this.framePoints = null; 
     } 
     if (this.framePoints == null) 
     { 
      switch (WindowFrameType) 
      { 
       case Forms.WindowFrameType.AllSides: 
        this.framePoints = new Point[5] 
        { 
         new Point(this.ClientRectangle.X, this.ClientRectangle.Y), 
         new Point(this.ClientRectangle.X + this.ClientRectangle.Width, this.ClientRectangle.Y), 
         new Point(this.ClientRectangle.X + this.ClientRectangle.Width, this.ClientRectangle.Y + this.ClientRectangle.Height), 
         new Point(this.ClientRectangle.X, this.ClientRectangle.Y + this.ClientRectangle.Height), 
         new Point(this.ClientRectangle.X, this.ClientRectangle.Y) 
        }; 
        break; 
       case Forms.WindowFrameType.LeftLine: 
        this.framePoints = new Point[2] 
        { 
         new Point(this.ClientRectangle.X, this.ClientRectangle.Y), 
         new Point(this.ClientRectangle.X, this.ClientRectangle.Y + this.ClientRectangle.Height) 
        }; 
        break; 
      } 
     } 
     return this.framePoints; 
    } 

    private void DrawWindowFrame(object sender, PaintEventArgs e) 
    { 
     if (WindowFrameType == Forms.WindowFrameType.NoFrame) 
     { 
      return; 
     } 
     if ((this.framePoints == null) || (this.framePoints.Length == 0)) 
     { 
      return; 
     } 
     Control ctrl = (Control)(sender); 
     // пересчитаем точки в координатах контрола. 
     List<Point> pts = new List<Point>(); 
     foreach (var p in this.framePoints) 
     { 
      pts.Add(ctrl.PointToClient(this.PointToScreen(p))); 
     } 
     e.Graphics.DrawLines(ActivePen, pts.ToArray()); 
    } 

    public static int WindowFrameSize = 2; 
    public static WindowFrameType WindowFrameType = Forms.WindowFrameType.NoFrame; 
    public static Color WindowFrameActiveColor = Color.YellowGreen; 
    public static Color WindowFrameInactiveColor = SystemColors.ControlDark; 
    public static double InactiveWindowOpacity = 1.0; 
    public static double WindowFrameOpacity = 0.3; 
    #endregion 

स्टेटिक क्षेत्रों आवेदन सेटिंग्स प्रपत्र (वर्ग) से प्रारंभ कर रहे हैं - तो, ​​सभी में रूपों ऐप का एक ही व्यवहार है।

आशा है कि किसी को मदद मिलेगी।

+0

मुझे इस प्रकार विंडोफ्रेम टाइप टाइप कहां मिल सकता है ?? – user1912383

संबंधित मुद्दे

 संबंधित मुद्दे