Tuesday, October 22, 2019
Programming a Class to Create a Custom VB.NET Control
Programming a Class to Create a Custom VB.NET Control Building complete custom components can be a very advanced project. But you can build a VB.NET class that has many of the advantages of a toolbox component with much less effort. Heres how! To get a flavor of what you need to do to create a complete custom component, try this experiment: - Open a new Windows Application project in VB.NET.- Add a CheckBox from the Toolbox to the form.- Click the Show All Files button at the top of Solution Explorer. This will display the files that Visual Studio creates for your project (so you dont have to). As a historical footnote, The VB6 compiler did a lot of the same things, but you never could access the code because it was buried in compiled p-code. You could develop custom controls in VB6 too, but it was a lot more difficult and required a special utility that Microsoft supplied just for that purpose. In the Form Designer.vb file, you will find that the code below has been added automatically in the right locations to support the CheckBox component. (If you have a different version of Visual Studio, your code might be slightly different.) This is the code that Visual Studio writes for you. Required by the Windows Form Designer Private components _ As System.ComponentModel.IContainerNOTE: The following procedure is requiredby the Windows Form DesignerIt can be modified using the Windows Form Designer.Do not modify it using the code editor.System.Diagnostics.DebuggerStepThrough() _Private Sub InitializeComponent() Me.CheckBox1 New System.Windows.Forms.CheckBox() Me.SuspendLayout() CheckBox1 Me.CheckBox1.AutoSize True Me.CheckBox1.Location New System.Drawing.Point(29, 28) Me.CheckBox1.Name CheckBox1. . . and so forth ... This is the code that you have to add to your program to create a custom control. Keep in mind that all the methods and properties of the actual CheckBox control are in a class supplied by the .NET Framework: System.Windows.Forms.CheckBox. This isnt part of your project because its installed in Windows for all .NET programs. But theres a lot of it. Another point to be aware of is that if youre using WPF (Windows Presentation Foundation), the .NET CheckBox class comes from a completely different library named System.Windows.Controls. This article only works for a Windows Forms application, but the principals of inheritance here work for any VB.NET project. Suppose your project needs a control that is very much like one of the standard controls. For example, a checkbox that changed color, or displayed a tiny happy face instead of displaying the little check graphic. Were going to build a class that does this and show you how to add it to your project. While this might be useful by itself, the real goal is to demonstrate VB.NETs inheritance. Lets Start Coding To get started, change the name of the CheckBox that you just added to oldCheckBox. (You might want to stop displaying Show All Files again to simplify Solution Explorer.) Now add a new class to your project. There are several ways to do this including right-clicking the project in Solution Explorer and selecting Add then Class or selecting Add Class under under the Project menu item. Change the file name of the new class to newCheckBox to keep things straight. Finally, open the code window for the class and add this code: Public Class newCheckBox Inherits CheckBox Private CenterSquareColor As Color Color.Red Protected Overrides Sub OnPaint( ByVal pEvent _ As PaintEventArgs) Dim CenterSquare _ As New Rectangle(3, 4, 10, 12) MyBase.OnPaint(pEvent) If Me.Checked Then pEvent.Graphics.FillRectangle( New SolidBrush( CenterSquareColor ), CenterSquare) End If End SubEnd Class (In this article and in others on the site, a lot of line continuations are used to keep lines short so they will fit into the space available on the web page.) The first thing to notice about your new class code is the Inherits keyword. That means that all the properties and methods of a VB.NET Framework CheckBox are automatically part of this one. To appreciate how much work this saves, you have to have tried programming something like a CheckBox component from scratch. There are two key things to notice in the code above: The first is the code uses Override to replace the standard .NET behavior that would take place for an OnPaint event. An OnPaint event is triggered whenever Windows notices that part of your display has to be reconstructed. An example would be when another window uncovers part of your display. Windows updates the display automatically, but then calls the OnPaint event in your code. (The OnPaint event is also called when the form is initially created.) So if we Override OnPaint, we can change the way things look on the screen. The second is the way Visual Basic creates the CheckBox. Whenever the parent is Checked (that is, Me.Checked is True) then the new code we provide in our NewCheckBox class will recolor the center of the CheckBox instead of drawing a checkmark. The rest is what is called GDI code. This code selects a rectangle the exact same size as the center of a Check Box and colors it in with GDI method calls. The magic numbers to position the red rectangle, Rectangle(3, 4, 10, 12), were determined experimentally. I just changed it until it looked right. There is one very important step that you want to make sure you dont leave out of Override procedures: MyBase.OnPaint(pEvent) Override means that your code will provide all of the code for the event. But this is seldom what you want. So VB provides a way to run the normal .NET code that would have been executed for an event. This is the statement that does that. It passes the very same parameter- pEvent- to the event code that would have been executed if it hadnt been overridden, MyBase.OnPaint. Using the New Control Because our new control is not in our toolbox, it has to be created in the form with code. The best place to do that is in the form Load event procedure. Open the code window for the form load event procedure and add this code: Private Sub frmCustCtrlEx_Load( ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles MyBase.Load Dim customCheckBox As New newCheckBox() With customCheckBox .Text Custom CheckBox .Left oldCheckBox.Left .Top oldCheckBox.Top oldCheckBox.Height .Size New Size( oldCheckBox.Size.Width 50, oldCheckBox.Size.Height) End With Controls.Add(customCheckBox)End Sub To place the new checkbox on the form, weve taken advantage of the fact that there is already one there and just used the size and position of that one (adjusted so the Text property will fit). Otherwise we would have to code the position manually. When MyCheckBox has been added to the form, we then add it to the Controls collection. But this code isnt very flexible. For example, the color Red is hardcoded and changing the color requires changing the program. You might also want a graphic instead of a check mark. Heres a new, improved CheckBox class. This code shows you how to take some of the next steps toward VB.NET object oriented programming. Public Class betterCheckBox Inherits CheckBox Private CenterSquareColor As Color Color.Blue Private CenterSquareImage As Bitmap Private CenterSquare As New Rectangle( 3, 4, 10, 12) Protected Overrides Sub OnPaint _ (ByVal pEvent As _ System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(pEvent) If Me.Checked Then If CenterSquareImage Is Nothing Then pEvent.Graphics.FillRectangle( New SolidBrush( CenterSquareColor), CenterSquare) Else pEvent.Graphics.DrawImage( CenterSquareImage, CenterSquare) End If End If End Sub Public Property FillColor() As Color Get FillColor CenterSquareColor End Get Set(ByVal Value As Color) CenterSquareColor Value End Set End Property Public Property FillImage() As Bitmap Get FillImage CenterSquareImage End Get Set(ByVal Value As Bitmap) CenterSquareImage Value End Set End PropertyEnd Class Why The BetterCheckBox Version Is Better One of the main improvements is the addition of two Properties. This is something the old class didnt do at all. The two new properties introduced are FillColor and FillImage To get a flavor of how this works in VB.NET, try this simple experiment. Add a class to a standard project and then enter the code: Public Property Whatever Get When you press Enter after typing Get, VB.NET Intellisense fills in the entire Property code block and all you have to do is code the specifics for your project. (The Get and Set blocks arent always required starting with VB.NET 2010, so you have to at least tell Intellisense this much to start it.) Public Property Whatever Get End Get Set(ByVal value) End SetEnd Property These blocks have been completed in the code above. The purpose of these blocks of code is to allow property values to be accessed from other parts of the system. With the addition of Methods, you would be well on the way to creating a complete component. To see a very simple example of a Method, add this code below the Property declarations in the betterCheckBox class: Public Sub Emphasize() Me.Font New System.Drawing.Font( _ Microsoft Sans Serif, 12.0!, _ System.Drawing.FontStyle.Bold) Me.Size New System.Drawing.Size(200, 35) CenterSquare.Offset( CenterSquare.Left - 3, CenterSquare.Top 3)End Sub In addition to adjusting the Font displayed in a CheckBox, this method also adjusts the size of the box and the location of the checked rectangle to account for the new size. To use the new method, just code it the same way you would any method: MyBetterEmphasizedBox.Emphasize() And just like Properties, Visual Studio automatically adds the new method to Microsofts Intellisense! The main goal here is to simply demonstrate how a method is coded. You may be aware that a standard CheckBox control also allows the Font to be changed, so this method doesnt really add much function. The next article in this series, Programming a Custom VB.NET Control - Beyond the Basics!, shows a method that does, and also explains how to override a method in a custom control.
Monday, October 21, 2019
Third Grade Christmas Word Problems
Third Grade Christmas Word Problems Word problems andà problem-solvingà questionsà helpà students to put the computations into authentic practice. Select questions that require a higher level thinking. Its also helpful to use questions that have more than one strategy available to solve them. Let students think about the way they solve their questions and let them draw pictures or use manipulatives to support their own thinking and logic. Try these Christmas-themed wordà problems for third graders to stay in the spirit of things in class: 1. Ivan is putting bulbs on the Christmas tree. He has already put 74 bulbs on the tree but he has 225. How many more bulbs does he have to put on the tree? 2. Amber has 36 candy canes to share among herself and 3 friends. How many candy canes will each of them get? 3. Kenââ¬â¢s new advent calendar has 1 chocolate for the 1st day, 2 chocolates on the 2nd day, 3 chocolates on the 3rd day, 4 chocolates on the 4th day and so on. How many chocolates will he have eaten by the 12th day? 4. It takes 90 days to save enough money to do some Christmas shopping. Estimate how many months that is. 5. Your string of Christmas lights has 12 bulbs on it, but 1/4 of the bulbs donââ¬â¢t work. How many bulbs do you have to buy to replace the ones that donââ¬â¢t work? 6. For your Christmas party, you have 5 mini pizzas to share with 4 friends. Youââ¬â¢re cutting the pizzas in half, how much will each friend get? How can you make sure the leftovers get shared equally? Print the PDF:à Christmas Word Problems Worksheet
Sunday, October 20, 2019
All About the Eighth Amendment to the US Constitution
All About the Eighth Amendment to the US Constitution The Eighth Amendment reads:Ã Excessive bail shall not be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted. Why Bail is Crucial Defendants who are not released on bail have greater difficulty preparing their defenses. Theyre effectively punished with imprisonment until their time of trial. Decisions regarding bail should not be made lightly. Bail is set extremely high or sometimes denied entirely when a defendant is charged with an extremely serious offense and/or if he poses a flight risk or great potential danger to the community. But in the majority of criminal trials, bail should be available and affordable. Its All About the Benjamins Civil libertarians tend to overlook fines, but the matter is not insignificant in a capitalist system. By their very nature, fines are anti-egalitarian. A $25,000 fine levied against an extremely wealthy defendant might only impact his discretionary income. A $25,000 fine levied against a less wealthy defendant can potentially have a long-term effect on basic medical care, educational opportunities, transportation and food security. Most convicts are poor so the issue of excessive fines is central to our criminal justice system. Cruel and Unusual The most frequently cited part of the Eighth Amendment deals with its prohibition against cruel and unusual punishment, but what does this mean in practical terms?Ã Dont ask the founding fathers:Ã The Crimes Act of 1790 mandates the death penalty for treason and it also mandates mutilation of the corpse. By contemporary standards, corpse mutilation would certainly be regarded as cruel and unusual. Floggings were also common at the time of the Bill of Rights, but today floggings would be regarded as cruel and unusual. The Eighth Amendment is more clearly affected by societal change than any other amendment in the Constitution because the very nature of the phrase cruel and unusual appeals to evolving societal standards.Torture and prison conditions: The Eighth Amendment certainly prohibits the torture of U.S. citizens in a contemporary context although torture is generally used as an interrogation method, not as an official form of punishment. Inhumane prison conditions also violate the Eighth Amendment even though they dont constitute part of the official sentence. In other words, the Eighth Amendment refers to de facto punishments whether the y are officially handed down as punishments or not. The death penalty: The U.S. Supreme Court found that the death penalty, which was applied capriciously and on a racially discriminatory basis, violated the Eighth Amendment in Furman v. Georgia in 1972. These death penalties are cruel and unusual, Justice Potter Stewart wrote in the majority opinion, in the same way that being struck by lightning is cruel and unusual. The death penalty was reinstated in 1976 after serious revisions were made.Specific methods of execution prohibited:Ã The death penalty is legal, but not all methods of enforcing it are. Some, such as crucifixion and death by stoning, are obviously unconstitutional. Others, such as the gas chamber, have been declared unconstitutional by courts. And still others, such as hanging and death by a firing squad, have not been regarded as unconstitutional but are no longer in common use.The lethal injection controversy: The State of Florida declared a moratorium on lethal injection and a de facto moratorium on the death pena lty as a whole after reports that Angel Diaz was essentially tortured to death during a botched execution. Lethal injection in humans is not simply a matter of putting the defendant to sleep. It involves three drugs. The strong sedative effect of the first is intended to prevent the excruciating effects of the latter two.
Saturday, October 19, 2019
Case X Essay Example | Topics and Well Written Essays - 1750 words
Case X - Essay Example Udon has none of these. Porter then goes back to her patrol car to call in the license plate. It turns out that the car, while registered to Udon, does not have current tags. Since Udons license plate displayed the current registration tag, Porter surmises, correctly, that Udon has stolen the tag. Porter also finds out that Udon does not have a drivers license, had never possessed a drivers license, and does not have insurance. Porter goes back to the car to talk to Udon, and then, upon coming back to the car, the policewoman notices the smell of alcohol on Udons breath. Therefore, Porter asks Udon to get out of the car so that she can give Udon the field sobriety test. However, Udon refuses, stating that she is pregnant and bleeding and needs to go to the hospital. Porter, having heard similar excuses 100 times a day from people who are trying to get out of a ticket or having to do a field sobriety test, refuses the request and continues to ask Udon to step out of the car so that Udon can take a field sobriety test. Udon continues to refuse, then finally relents. Since Udon was heavily intoxicated, she fails the field sobriety test in spectacular fashion, so Porter handcuffs her and takes her to the station. While in the car, Udon continually states that she is bleeding and needs to go to the hospital. Porter immediately assumes that, even if Udon is bleeding, it is probably because she is on her menstrual cycle and Udon was not to be trusted. After all, Udon gave Porter a false name, was driving in a car that was not registered, was driving intoxicated, and had neither a drivers license nor insurance. There was no reason for Porter to believe Udons story about having a miscarriage and needing to go to the hospital. And, as stated before, people, when pulled over, offer all kinds of excuses as to why they are speeding or why they cannot perform a field sobriety test.
Friday, October 18, 2019
Waiting for Godot Assignment Example | Topics and Well Written Essays - 500 words
Waiting for Godot - Assignment Example People who are interested in seeing literary works or who are more philosophical will be seeing this drama on stage. The theatrical presentation shows the characters talking about nothingness and hoping for Godot to come who never comes. They talk just for the sake of talking and end up doing nothing. When the audiences leave the theatre, they may have the feeling of analyzing their own situations with those of Vladimir and Estragon. The alienation and feeling of nothingness that the characters undergo may be transferred to the audience. The new style of theatre dramatizing plays like Waiting for Godot that have very less story in them and a message of nothingness and human pathetic condition. This theatre appeared applicable when people face crises in their lives and can relate their lives to the story played on the stage. The theatre is much more informative about human condition. The tramps shown in the play who have nothing to do and who think about committing suicide are depictive of the human condition in todayââ¬â¢s time of crises when people are trapped by the feeling of nothingness and they face conditions of solitude and seclusion. The tramps have no idea of time and space. Samuel Beckettââ¬â¢s Waiting for Godot was enough influential as people have not rejected the play as delivering some absurd story or valueless content, but they valued it as spectators and see themselves and their lives attached to the play. The second clip shows a somewhat converted version of Waiting for Godot and the story is named as Waiting for Elmo. This is a comic piece in which, two cartoon characters are waiting for Elmo and ponder over the notion that if Elmo never comes and they keep on waiting. In it, the tree starts leaving and is talking as it sees the two people waiting endlessly for Elmo who is not ready to
Exposed Essay Example | Topics and Well Written Essays - 500 words
Exposed - Essay Example When they were not ready to co-operate with me, I complained to my supervisor, and the same is not against anyone, but against the misconduct of the whole group. In addition, I would seek help from the supervisor to resolve the conflict and I will be ready to co-operate with my co-workers. On the other side, I would advise Jane that one must not use email to discuss sensitive or private information with co-workers/ supervisors. One can see that Harold Grimes dealt with Janeââ¬â¢s grievance/complaint in a professional manner. But Alisha Jones circulated files including the companyââ¬â¢s rules, added with Janeââ¬â¢s email. To be specific, Alisha Jones tried to convince the workers that one of them faces stress and alienation in his/her workplace. So, she forwarded the email as a proof. This increased the scope of further tension among the employees. So, I would advise Jane that email is not a safe mode of communication to discuss sensitive or private information with co-workers or supervisors. On the other side, she can directly contact Harold Grimes because his duty is to supervise the workers and to resolve the conflicts among them. First of all, I feel extremely sorry to say that I was forced to complain to our supervisor, on your rude behavior. You people were aware of the fact that I am a new member to our existing work team. I am not complaining, but pointing out some facts on workplace harassment/alienation face by me. You people had been together for a long time and it is your duty to amalgamate a new member to the core of the group. As far as I am concerned, I was so excited to work with an existing work team. But you people did not try to help me by sharing your own language and code of conduct with me. You people know that I tried my level best to co-operate, but for no use. For instance, you people used to share private
Thursday, October 17, 2019
Perceptions of performance feedback Essay Example | Topics and Well Written Essays - 2000 words
Perceptions of performance feedback - Essay Example ent follows though busy with commitments" and out of 15 people, no one strongly agreed, 14 agreed, 1 neither agreed nor disagreed and no one chose the rest of the options. The eleventh question was "Receive coaching and training" and out of 15 people, no one strongly agreed, 9 agreed, 6 neither agreed nor disagreed and no one chose the rest of the options. Questionnaire # 2 Perceived Perception of Change The first question was " I am part of the decision making process" and out of 15 people none strongly agreed, 2 agreed, 8 neither agreed nor disagreed, none strongly disagreed and 5 chose not applicable. The second question was "Thoughts and ideas are taken seriously" and out of 15 people, 1 strongly agreed, 10 agreed, 4 neither agreed nor disagreed and no one chose the rest of the two options. The third question was "Encouraged to offer solutions" and out of 15 people, none strongly agreed, 15 agreed and no one chose the rest of the options. The fourth question was "I take pride in working for the company" and out of 15 people 2 strongly agreed, 13 agreed and no one chose the rest of the options. The fifth question was "Promotes a family atmosphere" and out of 15 people, 12 strongly agreed, 3 agreed and no one chose the rest of the options. The sixth question was "Company values are compatible with my values" and out of 15 people, 12 strongly agreed, 2 agreed, 1 neither agreed nor disagreed and no one chose the rest of the options. The seventh question was "Company contributes to the community" and out of 15 people, 1 strongly agreed, 14 agreed and no one chose the rest of the options. The eighth question was "Would recommend the company to my friends" and out of 15 people, 4 strongly agreed, 6 agreed, 5 neither agreed nor disagreed and no one chose the rest of the... The third question was "Management makes frequent positive comments" and out of 15, 4 chose strongly agree, 9 chose agree, 2 chose neither agree nor disagree and no one chose strongly disagree and not applicable. The sixth question was "Supervisor cares about personal development" and out of 15 people, 5 chose strongly agree, 5 chose agree, 2 chose neither agree nor disagree and no one chose the rest of the two options. The seventh question was "Expectations are the same for everyone" and out of 15 people, 2 strongly agreed, 7 agreed, 5 neither agreed nor disagreed, 1 strongly disagreed and no one chose the last option. The tenth question was "Management follows though busy with commitments" and out of 15 people, no one strongly agreed, 14 agreed, 1 neither agreed nor disagreed and no one chose the rest of the options. The first question was " I am part of the decision making process" and out of 15 people none strongly agreed, 2 agreed, 8 neither agreed nor disagreed, none strongly disagreed and 5 chose not applicable. The first question was "I always have the supplies to do my job well" and out of 15 people, none strongly agreed, 6 agreed, 3 neither agreed nor disagreed, 6 strongly disagreed and no one chose the last option. The survey
Subscribe to:
Comments (Atom)