|
thank you, i had figured that out in the meantime as well
Though i still was looking for a way to make it work without using a constant, so i just tried without and it worked also.
I still don´t know when i have to declare a variable in the method and when not , i hope the understanding comes with doing more exercises.
Thank you both for your help
sbyte up = +1;
sbyte down = -1;
void WijzigVerdiep(sbyte direction )
{
etage += direction;
lblHuidigeVerdieping.Content = etage.ToString();
}
|
|
|
|
|
You're welcome!
But constants are a good idea here.
All they do is create a variable which can't be changed - the compiler will not let it appear on the left hand side of a "=" sign, or be passed as a method parameter that can be changed (you'll get to those later in the course).
They are also really easy to do: just put the keyword const at the start of the declaration (where you could put public or private ):
const sbyte up = +1;
const sbyte down = -1; And the compiler will not let any part of your code change the value.
That means you can't make a mistake, and change them accidentally - which could make your program to some strange things a lot later when it's difficult to spot.
You don't have to use them, but it's a good idea!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Add this method to your code, and then aim the click handler for both buttons at it.
private void btnUpDown_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
switch (btn.Name)
{
case "btnUp" : etage++; break;
case "btnDown" : etage--; break;
}
lblHuidigeVerdieping.Content = etage.ToString();
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 9-Mar-18 13:26pm.
|
|
|
|
|
Similarly, without numeric constants:
void WijzigVerdieping(bool omhoog) {
if (omhoog) etage++; else etage--;
lblHuidigeVerdieping.Content = etage.ToString();
}
private void btnUp_Click(object sender, RoutedEventArgs e) {
WijzigVerdieping(true);
}
private void btnDown_Click(object sender, RoutedEventArgs e) {
WijzigVerdieping(false);
}
which is using the predefined boolean constants true and false .
PS: you need some limit checks, otherwise pressing btnDown a lot might teleport you to Australia...
|
|
|
|
|
I assume there is a reason you defined the Enum used here; however, it makes no sense to use an Enum as a counter when you allow its value to go outside of the range for which you have defined Enum members.
Assumming you wish the Enum to define the range of "legal" counter values:
namespace Whatever
{
public enum Verdieping
{
kelder = -1,
gelijksvloers,
een,
twee,
drie
}
public partial class MainWindow : Window
{
private int tally;
public MainWindow()
{
InitializeComponent();
lblHuidigeVerdieping.Text = Verdieping.gelijksvloers.ToString()};
tally = 0;
}
private void TallyButtons_Click(object sender, RoutedEventArgs e)
{
if (sender.Equals(btnDown))
{
if (tally == (int)Verdieping.gelijksvloers)
{
return;
}
tally--;
}
else
{
if (tally == (int) Verdieping.drie)
{
return;
}
tally++;
}
lblHuidigeVerdieping.Text = tally.ToString();
}
}
}
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Hi everybody,
I would like to set a background image to a Groupbox and have it displayed at run time.
Below are the lines inserted in the xaml file at the appropriate locations:
<Window.Resources>
<VisualBrush x:Key="myNewBrush">
<VisualBrush.Visual>
<Grid>
<Rectangle Fill="Transparent"/>
<Image Source = "/Resources/Images/BartMap.png"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Windows.Resources>
<GroupBox Grid.Row="1" Grid.Column="0" Background="Transparent">
<GroupBox.Header>
<Label FontWeight="Bold">Track plan </Label>
</GroupBox.Header>
<Grid Background="{StaticResource myNewBrush}">
</Grid>
</GroupBox>
My problem: The image background is not displayed at runtime.
Could anyone help me with this issue?
Best regards,
Hervend
Hervend
|
|
|
|
|
|
The following is an add-in for MS Outlook. One can scan the body of an e-mail and if there is a certain (specific word or pattern) word present, then a MessageBox appears. However, I am wondering if it is possible to change the way a word appears or to edit the text in the body of email, without MessageBox whatsoever. For example, a word (such as the name of the company) can be converted into an hyperlink (i.e. Google to www.google.com or Microsoft to www.microsoft.com) and the user who reads emails on Outlook always sees the hyperlink instead of the word itself.
<pre lang="c#">using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Drawing;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace FirstOutlookAddIn
{
public partial class ThisAddIn
{
public static string[] data = new string[10];
public static Stopwatch timer = new Stopwatch();
Outlook.NameSpace outlookNameSpace;
Outlook.MAPIFolder inbox;
Outlook.Items items;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
timer = Stopwatch.StartNew(); ReadMail();
outlookNameSpace = this.Application.GetNamespace("MAPI");
inbox = outlookNameSpace.GetDefaultFolder(
Microsoft.Office.Interop.Outlook.
OlDefaultFolders.olFolderInbox);
items = inbox.Items;
items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ReadSingleMail);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
static void ReadSingleMail(dynamic item)
{
string bodyText;
string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (item != null)
{
bodyText = item.Body;
}
else
{
return;
}
}
static void ReadMail()
{
string bodyText;
string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items unreadItems = inboxFolder.Items.Restrict("[Unread]=true");
int max_runs;
if (unreadItems.Count > 10) { max_runs = 10; }
else max_runs = unreadItems.Count;
for (int counter = 1; counter <= max_runs; counter++)
{
for (int index = 0; index <= 8; index++)
{
data[index] = "";
}
dynamic item = unreadItems[counter];
bodyText = item.Body;
Match match = Regex.Match(bodyText, "Insert searched pattern here");
if (match.Success)
{
MessageBox.Show(match.Value);
match = match.NextMatch();
}
}
}
#region Von VSTO generierter Code
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
|
|
|
|
|
Not sure about Germany, but in many countries changing the content of mail messages would be viewed as illegal.
|
|
|
|
|
I don't think that the concept of an outlook-addin is illegal, similar to spellcheckers.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
It depends whether it is selected and installed by the user, or forced on them.
|
|
|
|
|
It "may" be enforced by company-policies. If it is without the knowledge and consent of the owner then it would always be illegal, regardless of what it does.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
A quick look on MSDN shows that the "Body" string is read/write, but I'm not sure whether that means that editing is supported from code.
I'd prefer saving those mails in a SQL Server and processing them there - also a lot easier with debugging in the future, and no dependency on (a specific version of) Outlook.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Creating the function ReadMail() as below replaces text, as I want it.
static void ReadMail(){
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items Items = inboxFolder.Items.Restrict("[LastModificationTime] > '01/1/2003'");
foreach (var item in Items){
var mail = (Outlook.MailItem)item;
mail.Body = mail.Body.Replace("Text to be replaced", "Replacing text");
mail.Save();
}
}
|
|
|
|
|
Hi,
how can i set windows form over other programs at the desktop in c#?
i mean i have a form that is like a tool bar that always
has to be at top on the screen and all other programs that are running(like chrome, ie..) should be below it.
the form must by always visible to the user (topmost=true), and will not hide part of other programs windows.
|
|
|
|
|
That's not really possible, even for a topmost window - which is above all the others - you can't prevent other applications from "using" part of the desktop: there is no way to stop an app from (for example) maximizing and expecting to get the whole screen.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
|
You're welcome.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I give users an option (check box) if they want a particular "window" "on top" (like a log).
Because, often a dialog / window they need to interact with will appear "below" this top window, and then they cannot interact with it (e.g. press "OK") because it is covered (and they don't know how to "move" it).
If a window has a "top most", at least allow the user to "minimize" it if it must always be "available".
I'll "flash" the title bar, so even if a window is minimized, the user knows I'm still "logging their mistakes" (or whatever).
(And "close" simply "hides" these windows; keeping content intact for the next item).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Desktop toolbars are a thing of the past, but if you must...
Keep in mind that some applications don't respect the new Desktop size taking into consideration the toolbar boundaries. They will go by screen size instead, which toolbars don't change, overlaying their window on top of your toolbar.
|
|
|
|
|
hi
i'm getting the following error when trying to push notification to multiple ios devices
Error:
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) when pushing notification to apple
any help?
Thank u
|
|
|
|
|
"any help?" How about, have you got any code?
|
|
|
|
|
not getting any code , just i'm getting that exception after pushing some tokens
|
|
|
|
|
If you don't show us any relevant code that you have written, you are just wasting our time and yours. You might as well just google what triggers that exception.
This space for rent
|
|
|
|